I am working with the following project structure
Project
|-Subproject1
|-Subproject2
|build.gradle
|settings.gradle
The submodules are included in the settings.gradle
and configured in the build.gradle
of the root project.
I have 3 tasks to do
build
(every subproject has this)deploy
(this is a packaging mechanism for every subproject needs to work on its own)finalizeDeployment
(this needs to be invoked only once)I want to be able to call
$gradle deploy
<- all subprojects get deployed and finalize gets called once at the end
$gradle Subproject1:deploy
<- Subproject1 gets deployed and finalize gets called
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'
}
}
It works the following way
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)
The Console output for gradle subproject1:deployFinalize
is:
Do Build subproject1
deploy subproject1
Finalize Deployment
The Console output for gradle deployFinalize
is:
Do Build subproject1
deploy subproject1
Do Build subproject2
deploy subproject2
Finalize Deployment