5

我正在使用以下项目结构

Project
|-Subproject1
|-Subproject2
|build.gradle
|settings.gradle

子模块包含在根项目的settings.gradle和配置中。build.gradle

我有 3 个任务要做

  1. build(每个子项目都有这个)
  2. deploy(这是每个子项目都需要自己工作的打包机制)
  3. finalizeDeployment(这只需要调用一次)

我希望能够打电话

$gradle deploy<- 所有子项目都被部署并最终被调用一次

$gradle Subproject1:deploy<- Subproject1 被部署并且 finalize 被调用

构建.gradle

configure(subprojects) {

    task build <<{
        println "Do Build "+ project.name
    }

    task deploy(dependsOn:build){
        println 'deploy '+project.name

        doLast{
            finalizeDeployment.execute()
        }
    }
}

task finalizeDeployment{

    dependsOn subprojects.deploy

    doLast{
        println 'Finalize Deployment'
    }
}
4

2 回答 2

5

它的工作方式如下

configure(subprojects) {

    task build << {
        println "Do Build " + project.name
    }

    task deployPrepare(dependsOn: build)<<{
            println 'deploy ' + project.name
    }

    task deployFinalize(dependsOn: deployPrepare)<<{
        parent.deployFinalize.execute()
    }
}

task deployFinalize {

    doLast {
        println 'Finalize Deployment'
    }
}

deployFinalize.dependsOn(subprojects.deployPrepare)

控制台输出为gradle subproject1:deployFinalize

Do Build subproject1
deploy subproject1
Finalize Deployment

控制台输出为gradle deployFinalize

Do Build subproject1
deploy subproject1
Do Build subproject2
deploy subproject2
Finalize Deployment
于 2013-04-24T16:21:07.037 回答
0

似乎您可以通过依赖项获得相同的功能,而无需使用 parent.deployFinalize.execute()。

在我工作的地方,我们使用:

subprojects {

   task dist(type: Copy, dependsOn: assemble) {
       ...
   }
}

task dist
dist.dependsOn subprojects.dist

task finalizeDist(dependsOn : subprojects.dist) {
    ...
}
dist.dependsOn finalizeDist
于 2015-06-04T19:38:39.360 回答