我正在使用以下项目结构
Project
|-Subproject1
|-Subproject2
|build.gradle
|settings.gradle
子模块包含在settings.gradle
中,并在根项目的build.gradle
中配置。
我有3个任务要做
build
(每个子项目都有此)deploy
(这是每个子项目需要独立工作的打包机制)finalizeDeployment
(这只需要调用一次)我希望能够致电
$gradle deploy
< - 所有子项目都已部署,最终确定在最后被称为一次
$gradle Subproject1:deploy
< - 部署Subproject1并调用finalize
的build.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'
}
}
答案 0 :(得分:4)
它的工作方式如下
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
答案 1 :(得分: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