forked from wenjing-bonnie/AndroidPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.gradle
73 lines (60 loc) · 2.05 KB
/
settings.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
rootProject.name = "AndroidPlugin"
include ':app'
include ':firstplugin'
include ':wjplugin'
include ':manifestplugin'
def prefix = "<<<<<<<settings.gradle<<<<<<<<<< "
//监听Gradle的生命周期需要放在settings.gradle中,否则有些方法无法监听到
this.gradle.addBuildListener(new BuildListener() {
@Override
void buildStarted(Gradle gradle) {
println(prefix + "buildStarted ")
}
@Override
void settingsEvaluated(Settings settings) {
println(prefix + "settingsEvaluated ")
}
@Override
void projectsLoaded(Gradle gradle) {
println(prefix + "projectsLoaded 已经完成Gradle构建的初始化阶段")
//会调用到对应的this.gradle.projectsLoaded{}
}
@Override
void projectsEvaluated(Gradle gradle) {
println(prefix + " projectsEvaluated 已经完成Gradle构建的配置阶段")
}
@Override
void buildFinished(BuildResult buildResult) {
println(prefix + "buildFinished 已经完成Gralde构建的执行阶段")
}
})
//在初始化结束后,可以输出所有的Project实例
this.gradle.allprojects {
Project project ->
// println(prefix + "allprojects Project name = " + project.name)
}
//循环每个build.gradle来构建task依赖关系图
this.gradle.beforeProject {
Project project ->
println(prefix + "beforeProject Project name = " + project.name)
}
this.gradle.afterProject {
Project project ->
//println(prefix + "afterProject Project name = " + project.name)
}
//输出task关系图中的所有task
this.gradle.taskGraph.whenReady {
// List<Task> taskList = this.gradle.taskGraph.allTasks
// for (Task task : taskList) {
// println(prefix + "in graph of task = " + task.name+" in project = "+task.getProject())
// }
}
//每个task的执行过程的监听
this.gradle.taskGraph.beforeTask {
Task task ->
// println(prefix + "beforeTask Task name = " + task.name)
}
this.gradle.taskGraph.afterTask {
it ->
// println(prefix + "afterTask Task name = " + it.name)
}