Skip to main content

Gradle : Introduction to Gradle Build Lifecycle

Gradle Build Lifecycle Phases

A gradle build has three phases

  1. Initialization - In this phase the gradle build is initialized. Gradle scans the project and its sub projects to create a Project instance of each project and sub project.
  2. Configuration - In this phase the gradle build is configured. In this phase a Task tree is created which determines how and when to run the tasks.
  3. Execution - In this phase the gradle build is executed. This phase actually runs the tasks configured in the configuration phase.

What are the Gradle Build Phases

Lets take the following example

build.gradle


println 'This is executed during the configuration phase.'

task configured {
println 'This is also executed during the configuration phase.'
}

task test {
doLast {
println 'This is executed during the execution phase.'
}
}

task testBoth {
doFirst {
println 'This is executed first during the execution phase.'
}
doLast {
println 'This is executed last during the execution phase.'
}
println 'This is executed during the configuration phase as well.'
}

The above example is self explanatory and tell you about the gradle build lifecycle phases. When run it will give the following output.

This is executed during the initialization phase.
This is executed during the configuration phase.
This is also executed during the configuration phase.
This is executed during the configuration phase as well.
:test
This is executed during the execution phase.
:testBoth
This is executed first during the execution phase.
This is executed last during the execution phase.

BUILD SUCCESSFUL

Total time: 1 secs

Also Read

Comments