Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Technically, the previous description about how to add extension methods to an existing class is a user-friendly way of doing it, but Groovy doesn't force you to use this standard mechanism. If you want to, you can write your own extension module implementation class, given that a module returns a list of MetaMethods to be added to a class. However, implementing such a module is not easy, and won't be covered by this tutorial. If you need to do that, please refer to the org.codehaus.groovy.runtime.m12n.ExtensionModule and org.codehaus.groovy.runtime.m12n.ExtensionModuleRegistry classes.

 

FAQ

Are extension modules compatible with type checking?

Yes, if the extension descriptor and the extension class is found on compilation classpath.

Are extension modules compatible with static compilation ?

Yes, if the extension descriptor and the extension class is found on compilation classpath.

When I compile my project using Gradle and @CompileStatic, my code using an extension module fails compilation.

As of Gradle 1.4, the Gradle incremental compiler doesn't seem compatible with extension modules. As a workaround, you can use the Ant compiler:

Code Block
compileGroovy.groovyOptions.useAnt = true
compileTestGroovy.groovyOptions.useAnt = true

See