Adding dependency for tasks which are part of subprojects


I am trying to add dependency for a main project task on few subprojects task based on say naming pattern. somehow below script is not working.

Can anyone please help what am I missing here?

task myTask {

println “inside myTask”

subprojects.each { CurProject ->

println “Project $ before dependent on”

CurProject.tasks.findAll { task ->

println “$ before dependent on”‘cur’).each {

println “$ dependent on”

dependsOn task



} }

There are a number of issues with this. Your biggest issue could be ordering the configuration. That is, the tasks may not exist yet when this code runs in the root project. A better way to do this would be the following:

subprojects {
    tasks.all {
         if ('cur')) {
            myTask.dependsOn it

tasks.all is a domain object collection that allows you to register a config hook for all tasks that have already been created as well as any new task that gets created later.

Thanks Gary… It worked…