Adding dependency for tasks which are part of subprojects

Hi,

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 $CurProject.name before dependent on”

CurProject.tasks.findAll { task →

println “$task.name before dependent on”

task.name.startsWith(‘cur’).each {

println “$task.name 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 (it.name.startsWith('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…