Gradle and local AST transformations


(Matt Cholick) #1

Groovy’s AST transformations are an area that’s new to me, so apologies if I’ve missed something. My understanding of local AST transformations is that the compiler only needs to see them in the source to apply them. When I’m compiling with Gradle, I’m not seeing my transformations being applied.

Here is a small sample project demonstrating this: https://github.com/mcholick/gradle_ast

When I run the test source from IntelliJ, I see that the transformation is applied (the new method is present).

When I run project using Gradle’s application plugin, I don’t see the transformation applied to my main source class, despite the same marker annotation being present.

Is there something I need to do to get Gradle’s Groovy compile to pick up a local AST transformation?


(Peter Niederwieser) #2

An AST transformation needs to be compiled using a separate ‘GroovyCompile’ task, and then put on the compile class path of any code that uses the transform. Perhaps IntelliJ has some special machinery to make this happen behind the scenes, but groovyc and Gradle don’t.