Reputation: 4742
I'm an idiot or something, and I don't know how to add groovy into src/groovy and make it work. Lets say I got some meta stuff in my bootstrap and I want to move those calls to a class I can call from unit tests or wherever based on this question: Correct way to metaprogram in grails so its available in unit tests
So if I put this in my bootstrap (which has import myproject.*
at the top) it works.
ExpandoMetaClass.enableGlobally()
Integer.metaClass.gimmeAP = {->return 'p'}
assert 3.gimmeAP() == 'p'
So I'm using STS and I go into src/groovy and say "New GroovyClass" add it to package myproject and fill it in as so:
package yakit
class MetaThangs {
def doMetaThangs() {
ExpandoMetaClass.enableGlobally()
Integer.metaClass.gimmeAP = {->return 'p'}
}
}
Then I call this in bootstrap:
MetaThangs.doMetaThangs()
assert 3.gimmeAP() == 'p'
I get the error:
Running Grails application..
2012-02-07 14:12:13,332 [main] ERROR context.GrailsContextLoader - Error executing bootstraps: groovy.lang.MissingMethodException: No signature of method: static lrnmeta.MetaThangs.doMetaThangs() is applicable for argument types: () values: []
Possible solutions: doMetaThangs()
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: static lrnmeta.MetaThangs.doMetaThangs() is applicable for argument types: () values: []
Possible solutions: doMetaThangs()
at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:251)
at grails.util.Environment.executeForEnvironment(Environment.java:244)
at grails.util.Environment.executeForCurrentEnvironment(Environment.java:220)
at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)
at grails.web.container.EmbeddableServer$start.call(Unknown Source)
at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
at RunApp$_run_closure1.doCall(RunApp:33)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:590)
at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: groovy.lang.MissingMethodException: No signature of method: static lrnmeta.MetaThangs.doMetaThangs() is applicable for argument types: () values: []
Possible solutions: doMetaThangs()
at BootStrap$_closure1.doCall(BootStrap.groovy:5)
... 26 more
Application context shutting down...
Application context shutdown.
Is it really telling me I should be typing 'doMetaThangs()' instead of 'doMetaThangs()'?
UPDATE: based on @mkoryak answer I have tried changing the method declaration in MetaThangs.groovy to:
static def doMetaThangs(){
...
}
It didn't work at first, but eventually it came around.
Upvotes: 0
Views: 475
Reputation: 57938
doMetaThangs is not static, but you are calling it as if it was.
either add the static modifier to the method, or call it on an instance of the class, not the class.
Upvotes: 1