Issue with doWithDynamicMethods in plugins
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
This is an old issue and reported earlier here on github. (https://github.com/grails/grails-core/issues/9648)
### 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())`
It did not work. So I tried enabling `ExpandoMetaClass` globally and it worked. But this is not efficient way to fix this. So looking for proper solution to fix this.
The issue reported earlier has two participants @jeffbrown & @graemerocher. Tagging them just to know their opinion on this, as they have already gone through this error.
### Environment Information
- **Operating System**: Windows 8.1
- **Grails Version:** 4.0.4
- **JDK Version:** 1.8
- **Container Version (If Applicable):** Wildfly 21, Websphere AS 8.5.5
Contributor guide
Research direction
Start with the plugin descriptor's doWithDynamicMethods implementation and compare this report with the earlier issue at github.com/grails/grails-core/issues/9648. Reproduce the cross-plugin ExperimentService.performOperation call on Grails 4.0.4 with and without global ExpandoMetaClass, then identify a supported solution that makes the dynamic method available without global enablement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100