假设有3个子项目:sub1,sub2和sub3。他们都有任务uploadArchives
。如果我们运行gradle uploadArchives
,它是如何级联到子项目的?
答案 0 :(得分:1)
假设你的项目布局如下:
gradle-tasks
|- sub1
|- sub2
|- sub3
settings.gradle
如下:
include 'sub1', 'sub2', 'sub3'
rootProject.name = 'gradle-tasks'
你的build.gradle
是这样的:
allprojects {
task uploadArchives {
doLast { task ->
println "I'm $task.project.name"
}
}
}
然后当您在root中执行./gradlew uploadArchives
时,您将拥有
$ ./gradlew uploadArchives
> Task :uploadArchives
I'm gradle-tasks
> Task :sub1:uploadArchives
I'm sub1
> Task :sub2:uploadArchives
I'm sub2
> Task :sub3:uploadArchives
I'm sub3
参考:https://docs.gradle.org/current/userguide/multi_project_builds.html