I have written a Groovy AST Transformation which only runs for me when Grails auto-reloads the class it is to be applied to. If I clean the project and start the application using run-app, the AST transformation does not run. Touching the class so that grails auto-reloads results in the transformation running.
The annotation and ASTTransformation implementation are groovy classes located in the src/groovy directory in my Grails application. The annotation is used on domain classes, written in groovy in the domain directory.
Is it possible this is caused by the order the groovy files get compiled or when they are loaded by the classloader? If so, how do I ensure my ast transforamtion is compiled/loaded before the domain classes?
The annotation:
@Target([ElementType.TYPE])
@Retention(RetentionPolicy.RUNTIME)
@GroovyASTTransformationClass(["com.abc.annotation.SecuredObjectASTTransformation"])
public @interface SecuredObject {
}
The ASTTransforamtion implementation:
@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
class SecuredObjectASTTransformation implements ASTTransformation {
@Override
public void visit(ASTNode[] nodes, SourceUnit sourceUnit) {
// add some new properties...
}
}
The Grails version is 2.1.0.