Gradle combines the power and flexibility of Ant with the dependency management and conventions of Maven into a more effective way to build. Powered by a Groovy DSL and packed with innovation, Gradle provides a declarative way to describe all kinds of builds through sensible defaults. Gradle is quickly becoming the build system of choice for many open source projects, leading edge enterprises and legacy automation challenges.

The calls doFirst and doLast can be executed multiple times. They add an action to the beginning or the end of the task?s actions list. When the task executes, the actions in the action list are executed in order.

//This is a defintion
someFunc = {some-closure}
//This is an invocation
someFunc()
//This is different meaning
//Call func that takes closure
someOtherFunc(someFunc)
//Same as above but closure is on the fly
someOtherFunc {some-closure}

* There are 2 different points in time when code related to a task is executed: The first is configuration time, which is when the build script executes. The idea is that at this time you configure the task, so that it does the right thing at the other point in time, namely, execution time. Execution time is the point in time where the task does its actual work, and happens only if the task is selected for execution, and after its dependencies have executed.

* Each task has a sequence of actions, which are run in the order specified when the task executes. An action is simply a closure or an Action implementation. The doFirst() method configures the task to add an action at the start of the sequence. The doLast() and << methods configure the task to add an action at the end of the sequence.

satya - 7/12/2018, 1:07:11 PM

Syntax analyze this

//same as task("hello", closure)
//using the syntax simplification of Groovy
task hello {
doLast {
println 'Hello world!'
}
}
//Inside the closure which gets to run
//as part of defining the task,
//the code calls
task.doLast(closure)
//the last closure is the
print hello world

The buildScript block determines which plugins, task classes, and other classes are available for use in the rest of the build script. Without a buildScript block, you can use everything that ships with Gradle out-of-the-box. If you additionally want to use third-party plugins, task classes, or other classes (in the build script!), you have to specify the corresponding dependencies in the buildScript block.