gradle如何解释在父级别运行的命令

时间:2017-11-24 00:22:59

标签: gradle

假设有3个子项目:sub1,sub2和sub3。他们都有任务uploadArchives。如果我们运行gradle uploadArchives,它是如何级联到子项目的?

1 个答案:

答案 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