I'm completely new to both gradle and groovy and I'm having trouble to find information about what the below actually is in the groovy language
task myTask(dependsOn: 'compile') << {
println 'I am not affected'
}
AFAIK the {...}
part is a closure which seems to be passed to whatever is defined before <<
.
Is task myTask()
a call to a constructor?
And what is the thing with the colon that looks like a parameter?
What does <<
do? Is it an operator that was overloaded by gradle or is it standard groovy?
Defining Gradle Tasks You define a Gradle task inside the Gradle build script. You can define the task pretty much anywhere in the build script. A task definition consists of the keyword task and then the name of the task, like this: task myTask. This line defines a task named myTask .
Keyword def comes from Groovy and means that variable has local scope. Using ext. outDir means that you add property outDir to ExtraPropertiesExtension, think of it like project has a map of properties with name ext , and you put your property in this map for later access.
It is popular for its ability to build automation in languages like Java, Scala, Android, C/C++, and Groovy. The tool supports groovy based Domain Specific Language over XML. Gradle provides building, testing, and deploying software on several platforms. The tool is popular for building any software and large projects.
A custom task type is a simple Groovy class which extends DefaultTask – the class which defines standard task implementation. There are other task types which we can extend from, but in most cases, the DefaultTask class is the appropriate choice.
dependsOn: 'compile'
is a named argument. <<
is an overloaded operator that adds a task action to the task. (See Gradle User Guide for more information.) { ... }
is a closure that implements the task action. myTask
is syntactically a nested method call (task(myTask(dependsOn: 'compile') << ...)
), but gets rewritten to a String using a Groovy compiler plugin (task('myTask', dependsOn: 'compile') << ...
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With