5

Having upgraded to Grails 2.3.5 I found my mixins only work when JVM forking is turned off.

All my controllers have code like this

import util.MyMixin

@Mixin(MyMixin)
class MyController {

Where MyMixin is defined in src/groovy/util and looks something like

package util

class MyMixin {
    private def aMethod(someArgs) {
        // do something
    }
}

When the BuildConfig.groovy contains the following code

forkConfig = [maxMemory: 1024, minMemory: 64, debug: false, maxPerm: 256]
grails.project.fork = [
   test: forkConfig, // configure settings for the test-app JVM
   run: forkConfig, // configure settings for the run-app JVM
   war: forkConfig, // configure settings for the run-war JVM
   console: forkConfig // configure settings for the Swing console JVM
]

Then I get the following error

MissingMethodException occurred when processing request:
No signature of method: MyController.aMethod() is applicable for argument types

Where the argument types match and of course the code works when I don't have the JVM forking code in BuildConfig.groovy.

Is there something special I need to do to get mixins to work when forking the JVM? I'm only using forking because Grails 2.3.5 recommends it and I had problems when I didn't use it: Grails 2.3.5 requiring "grails clean" after every code change

Community
  • 1
  • 1
Jason
  • 11,709
  • 9
  • 66
  • 82
  • This is [grails](http://grails.org/doc/latest/api/grails/util/Mixin.html) or [groovy](http://groovy.codehaus.org/gapi/groovy/lang/Mixin.html) @Mixin? – dmahapatro Feb 17 '14 at 19:46
  • I didn't know there was a difference. How do I tell? There is nothing in the imports with "Mixin"... should there be? – Jason Feb 17 '14 at 19:54
  • Then I guess you are using `groovy.lang.Mixin`. Try using the other. – dmahapatro Feb 17 '14 at 21:53
  • Okay... so I tried to explicitly use grails and groovy Mixins with the following code `@groovy.lang.Mixin(MyMixin)` and `@grails.util.Mixin(MyMixin)` and the groovy mixin worked while the grails mixin failed. Should I be concerned about this? What's the best way to resolve the problem? Change all my mixins to explicitly reference groovy mixin? – Jason Feb 17 '14 at 22:03
  • Well, now that's interesting. Today, neither `@groovy.lang.Mixin` nor `@grails.util.Mixin` work. – Jason Feb 18 '14 at 20:38
  • Sometimes mixins are working, sometimes they're not. Some controllers work, some don't. It's unclear what the variables are that are causing things to work or fail... I'll have to debug this on my own for a while until I have reproducible results. – Jason Feb 18 '14 at 20:58
  • If you file an issue at http://jira.codehaus.org/browse/GRAILS with a simple sample app we will take a look. – Jeff Scott Brown Apr 30 '14 at 12:54

1 Answers1

0

I've had a tough time using Mixins with Grails Domain objects and am not surprised to hear that you've had a rough go with Controllers. Domains, Controllers, and Services are so heavily managed by Grails, it's no wonder that normal @Mixins might get broken somehow. I have had success specifically injecting methods via the metaClass builder DSL as in:

targetClass.metaClass {
    someMethod { someParam ->
        // do something
    }
}

You have to call this yourself on all the target classes... It's not as elegant as @Mixin, but it seems to work.

augustearth
  • 281
  • 2
  • 10