In my last Grails 2.3.0 project, I use the @Mixin annotation to mix a helper class so that my controller more DRY.
The mixin just works if the changes made to the controller make the controller recompile. After the initial compilation ( grails run-app ), the helper does not mix - I get a MissingMethodException trying to access the method from the helper class.
Here is my witin src/groovy helper:
class ProjectHelper { def withProject(id, Closure c) { def project = Project.get(id) if (project) { c.call project } else { flash.message = 'Project not found!' render view: 'myView' return } } }
And (one of) the controller that uses ProjectHelper :
@Mixin(ProjectHelper) class ProjectController { def index() { withProject params.projectId, {project ->
When I clean up the project using grails clean and run the application, I get the following error after accessing project/index :
MissingMethodException occurred when processing request: [GET] /<myApp>/project/ No signature of method: <myPackage>.withProject() is applicable for argument types: (java.lang.String, <myPackage>.ProjectController$_index_closure1_closure10) values: [1, <myPackage> .ProjectController$_index_closure1_closure10@40d889b5 ]
After some changes to the ReportController (for example, with the addition of a single space), grails compiles 2 source files and the withProject method can be used. Access to project/index works as expected.
What's going on here? Is this a mistake or am I missing something?
Update
It turns out I completely missed that using grails.util.Mixin gives me another exception ( MissingPropertyException ) due to the lack of access to the mixed properties of the class (in my case: flash ) (see JIRA this issue ) that works with groovy.lang.Mixin (after recompilation).
Is there a way to manually recompile / paste / mixin groovy.lang.Mixin at runtime or do I need to find another error handling for the else part until the problem is fixed?
Any suggestions?