I wrote a Groovy AST Transformation, which only works for me when Grails automatically reloads the class to which it should be applied. If I clean up the project and run the application using run-app, the AST transformation fails. Touching the class so that automatic reloading of grails starts the conversion.
The annotation implementation and ASTTransformation are Groovy classes located in the src / groovy directory in my Grails application. Annotations are used for domain classes written in Groovy in the domain directory.
Is it possible that this is due to the compilation order of the Groovy files, or when they are loaded by the class loader? If so, how can I ensure that my ast transformation is compiled / loaded to domain classes?
Annotation:
@Target([ElementType.TYPE]) @Retention(RetentionPolicy.RUNTIME) @GroovyASTTransformationClass(["com.abc.annotation.SecuredObjectASTTransformation"]) public @interface SecuredObject { }
Implementation of ASTTransforamtion:
@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION) class SecuredObjectASTTransformation implements ASTTransformation { @Override public void visit(ASTNode[] nodes, SourceUnit sourceUnit) {
Grails version is 2.1.0.
source share