Reputation: 1549
I have 3 gradle tasks: A, B, C. B dependsOn A. C dependsOn A.
If have an if check in A that I want to be true when B runs, false when C runs. How do I do that?
For clarity, the real tasks are:
war { // task A
webAppDirName = 'src/main/webapp'
if (flag) {
rootSpec.exclude("**/*.json")
rootSpec.exclude("**/*.xml")
}
}
ospackage { // task B
buildRpm {
dependsOn war
}
}
task localTomcat { // task C
dependsOn war
}
I tried setting war.flag, war.ext.flag before dependsOn, in a doFirst action, but nothing...
Upvotes: 3
Views: 4170
Reputation: 1549
I found a solution using a dependsOn chain and mustRunAfter.
Code:
task war4pkg {
doLast {
war.rootSpec.exclude("**/*.json")
war.rootSpec.exclude("**/*.xml")
}
}
war {
webAppDirName = 'src/main/webapp'
}
ospackage {
buildRpm {
dependsOn war4pkg, war # order doesn't matter
war.mustRunAfter war4pkg # order set here
}
}
task localTomcat {
dependsOn war # nothing here.
}
Upvotes: 1