Understanding the groovy syntax in a gradle task definition

Gradle uses AST Transformations to extend the Groovy syntax. The task definition syntax you mention is just one of the transformations Gradle applies. You can find the implementation for that transform here. To answer your specific questions:

  • The individual transforms that Gradle applies are not specifically documented anywhere that I’m aware of. You could however look at the other classes in the same package of the link above.

  • Gradle scripts support a super-set of Groovy syntax. Any valid Groovy is also valid in a Gradle script, however, a Gradle script is not necessarily (and typically not) valid “default” Groovy.

  • There isn’t a way to get an output of the equivalent Groovy code since it’s the actual abstract syntax tree that is being manipulated in-memory.

Leave a Comment