Gradle : Introduction to Gradle Build Lifecycle
Gradle Build Lifecycle Phases
A gradle build has three phases
Initialization
- In this phase the gradle build is initialized. Gradle scans the project and its sub projects to create aProject
instance of each project and sub project.Configuration
- In this phase the gradle build is configured. In this phase aTask tree
is created which determines how and when to run the tasks.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
No comments: