IanWatson
IanWatson

Reputation: 1739

Gradle Task Configuration vs Task Execution

What is the difference between the code below?

task A {
 println 'configuration'
}

task B << {
 println 'action'
}

I believe it has something to do with evaluation.

ie task A is always evaluated whereas task B is only evaluated when its executed

Upvotes: 4

Views: 6624

Answers (1)

roomsg
roomsg

Reputation: 1857

Indeed: the 'println' statement of your task A will be executed during 'configuration' phase, whereas the 'println' statement of taks B will only be executed during 'execution' phase (assuming task B is run, directly or indirectly via task dependencies)

For more info, checkout: http://www.gradle.org/docs/current/userguide/build_lifecycle.html. Section 56.2 has a nice example (also demonstrating the third phase, being the 'initialization' phase, BTW)

Note: the "<<" is a shorthand notation for "doLast"

Upvotes: 7

Related Questions