Task Depends on Subproject Tasks?


(Ken) #1

Hi,

I have a Root Project that is basically a container for multiple other projects and does not host any real code. I want to wrap Maven publishing like so:

task publishAndSayHi {
    dependsOn('publishToMavenLocal')
    dependsOn('sayHi')
}

This will not work however because ‘publishtoMavenLocal’ only exists on the sub projects, not the root (as it has no code as I mentioned). I can do like so:

task publishAndSayHi {
    dependsOn(':subProj1:publishToMavenLocal')
    dependsOn(':subProj2:publishToMavenLocal')
    dependsOn(':subProj3:publishToMavenLocal')
    dependsOn('sayHi')
}

But I was wondering if perhaps there is more elegant way to do so without manually defining the sub projects?


(Eric Wendelin) #2

Well you could use a little Groovy syntax sugar to make it prettier like so:

task publishAndSayHi {
    subprojects.each { dependsOn("${it.name}:publishToMavenLocal") }
    dependsOn('sayHi')
}

Alternatively, if you don’t want to do this for all subprojects you can just define an Array.


(Ken) #3

Excellent, thank you very much!


(Sangeetha Radhakrishnan) #4

Thank you so much, this solution worked for me.