Issue with grails doWithDynamicMethods in plugins

74 Views Asked by At

The similar issue is reported on grails-core repository on github. But it is not answering all questions I am having and not working (partially).

Issue reported on github

Grails version: 4.0.3

Project Structure:

Main Project
+---  CommonPlugin
+---  AddonPlugin

Plugin Descriptor Snippet:

class AddonGrailsPlugin extends Plugin {
    ...
    void doWithDynamicMethods() {
        ExperimentService.metaClass.performOperation = { ExperimentCmd cmd ->
            ..
            < METHOD_FUNCTIONALITY >
            ...
            return < RETURN_ELEMENTS >;
        }
    }
    ...
}

And then trying to access method from CommonPlugin throws below error.

No signature of method: com.test.services.ExperimentService.performOperation() is applicable for argument types: (com.test.commands.ExperimentCmd) values: [com.test.commands.ExperimentCmd@1ab5698]
Possible solutions: performOperation(com.test.commands.ExperimentCmd)

Have followed resolution step provided on the link above and added code to plugin descriptor class.

ExperimentService.metaClass = GroovySystem.metaClassRegistry.getMetaClass(ExperimentService.getClass())

But it does not works. So followed the approach to enable ExpandoMetaClass globally and it does works perfectly.

Question:

  • Any plugin specific solution available to update metaClass to reflect newly added method from doWithDynamicMethods() or the only solution is to enable ExpandoMetaClass globally?
0

There are 0 best solutions below