Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are gradle task definitions in groovy language?

Tags:

gradle

groovy

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?

like image 236
ben Avatar asked Aug 31 '14 13:08

ben


People also ask

How are Gradle tasks defined?

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 .

What is def in Gradle?

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.

What is Gradle in Groovy?

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.

What is Groovy task?

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.


1 Answers

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') << ...).

like image 73
Peter Niederwieser Avatar answered Oct 25 '22 00:10

Peter Niederwieser