Gradle的生命周期

Gradle生命周期分三个阶段

Build phases

A Gradle build has three distinct phases.

  • Initialization

    Gradle supports single and multi-project builds. During the initialization phase, Gradle determines which projects are going to take part in the build, and creates a Project instance for each of these projects.

  • Configuration

    During this phase the project objects are configured. The build scripts of all projects which are part of the build are executed.

  • Execution

    Gradle determines the subset of the tasks, created and configured during the configuration phase, to be executed. The subset is determined by the task name arguments passed to the gradle command and the current directory. Gradle then executes each of the selected tasks.

1
2
3
4
5
6
7
8
9
10
11
12
//配置阶段前的监听回调
this.beforeEvaluate {
println '配置前阶段-->ok'
}
//配置阶段以后的监听回调
this.afterEvaluate {
println '配置后阶段-->ok'
}
//gradle执行完成以后的监听回调
this.gradle.buildFinished {
println '执行阶段-->ok'
}

参考

Gradle官网