a few words about groovy and gradle

In order to write the Jenkins pipeline, I learned the basic syntax of the groovy programming language several weeks ago. groovy is a scripted language based on Java Virtual Machine. It adopts most of the Java grammars, with a few addition, modification and enhancement. It is widely used in Jenkins and Gradle, which are two important tools implementing continuous integration in Java ecosystem. The official document about groovy can be found below:


With the basic knowledge about groovy in mind, I reviewed the syntax of writing a gradle file for building Java project. However, I was confused by the below Task syntax:

task intro (dependsOn: hello) {
doLast { println “I’m Gradle” }

I know this snippet is a valid gradle task, but what confuses me is that this code snippet does not seem to be a valid groovy code. After searching it using google, I find the answer to the question as below:


The key points are as below:

1. gradle uses a dedicated DSL, which utilizes groovy.

2. gradle uses AST transformation to extend the groovy syntax.

This means the above task definition is specific to gradle DSL. It can be not a valid groovy script. gradle will use groovy AST transformation to transform the gradle DSL into valid groovy script. The AST transformation code for the above task is as below:


3. the AST transformation applied by gradle is not universally documented. There are other AST transformations besides the gradle task definition in gradle.

4. gradle script is a superset of groovy script. Any groovy script is valid gradle script, but in the verse, any gradle script may not be a valid groovy script.