Task configuration

We discussed in first chapter that a build file consists of three phases: initialization, configuration, and execution, which are explained briefly as follows:

  • Initialization creates the project object.
  • The configuration phase configures the project object, creates DAG (Directed Acyclic Graph) based on task dependencies. It also executes the project and the task configuration statements.
  • The execution phase finally executes the actions mentioned in the task body.

The task API mainly defines two types of closures: doFirst(Closure closure) and doLast(Closure closure), which internally calls doFirst(Action action) and doLast(Action action). You can mention either one or both of them.

Tip

Statements mentioned outside of these actions are part of your configuration, which are executed during the configuration phase.

To verify the configuration phase of a task, you can execute the build script using the --dry-run or –m option. The --dry-run ( or –m) option only goes through the initialization and configuration phase, not the execution phase. Try to execute the preceding build file with the --dry-run option and you will find all the configuration statements printed on the console:

$ gradle --dry-run
This is project configuration part, description is Sample Java Project
This is sampleTask1 configuration statements, taskDetail is  This is custom property of task1
This is sampleTask2 configuration statements
:help SKIPPED

BUILD SUCCESSFUL

In Gradle 2.4 version, there are some performance improvements implemented in the configuration phase. For more details, refer to the release note at https://docs.gradle.org/2.4/release-notes#significant-configuration-time-performance-improvements.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.83.176