Gradle task syntax: how is it explained from a Groovy perspective?
13:11 05 Jul 2019

I'm having a hard time understanding how Gradle's Groovy DSL works.

Unfortunately Gradle is the main use-case for Groovy that I come across in my day to day work, and I've noticed that for many devs, their exposure to Groovy is strictly through Gradle. And that a majority of Gradle users have a very limited grasp of Groovy as a consequence.

In my limited understanding of Groovy, the following sintax tokenA tokenB { tokenC } where all tokens are not language keywords, tokenA would be a method that we are calling with arguments tokenB and the final argument is a closure. I would like to think I'm correct, but I know I'm wrong because there probably needs to be a comma after tokenB for that analysis to be correct.

I am by no means, as you can already tell, a Groovy dev, and I think using Gradle without learning the basics of Groovy is a bad thing to do, because it limits me from fully exploiting its capabilities. But my only viable option is to learn though examples without learning the theory unfortunately.

I did check out some similar questions like this one but no answers where clear or complete enough for me.

TL;DR

  1. How are the tokens task myTask { doLast {} } interpreted in Groovy?
  2. Does Gradle use a standard Groovy interpreter?
  3. How is myTask interpreted as an identifier when there is task and not def or a type behind it?
  4. If later in the file I added myTask { dependsOn myOtherTask } how does that get interpreted?
gradle groovy dsl