Groovy Compilation in Plugin Follow
Hi All,
I am writing a plugin to help with test automation. The plugin works fine except that I synthesize a Groovy class in the plugin, then compile it and auto-add it to the classpath...
When deployed the compilation fails with the following errors when I use AST annotations, e.g. @Field:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Missions: Not an ASTTransformation: org.codehaus.groovy.transform.FieldASTTransformation declared by groovy.transform.Field
Missions: AST transformation implementation classes must be annotated with org.codehaus.groovy.transform.GroovyASTTransformation. org.codehaus.groovy.transform.FieldASTTransformation lacks this annotation.
I am compiling the Groovy from a String as follows:
def className = MISSIONS_CLASS
CompilerConfiguration compilerConfiguration = new CompilerConfiguration()
compilerConfiguration.setTargetDirectory(PathManager.pluginsPath + "/tesseraplugin/classes")
CompilationUnit compileUnit = new CompilationUnit(compilerConfiguration)
compileUnit.addSource(className, scriptBuffer.toString())
Without the annotations, everything works completely smoothly...
Any thoughts?
Regards,
Simon
Please sign in to leave a comment.
OK, I figured it out myself, I had to create a GroovyClassLoader from the PluginClassLoader then pass that into the CompilationUnit creation...