I can understand most of the syntax of Gradle in terms of Groovy but the syntactic role of ‘task’ in this context eludes me. I assume ‘sometask’ is a method call (to an undefined method) with a map and a closure as arguments, that Gradle intercepts and uses to define ‘sometask’. But I’m not clear about the syntactic role of ‘task’. Is it a method call or something else?
It’s hard to understand because it’s actually transformed at compile time. Defining tasks is such a common thing to do so we added some syntactic sugar.
If you have:
task myTask(type: Copy) {
}
During compile time this is actually transformed to:
task("myTask", type: Copy) {
}
Which is a syntax you can also use if you need to.
We do this with the help of Groovy’s AST transformation capability.
Ok, is this the only place where Gradle syntax deviates from Groovy’s? Or is there a list somewhere of the differences?
There is one other area where we use AST transformations. This is the buildscript block:
buildscript {
...
}
The syntax is groovy, but as it adds to the script classpath, it is evaluated before the actual Groovy build script is compiled.
There is no place where we explicitly document the place where we use Groovy AST’s.
Good to know. Thanks.