How to run defaults tasks of sub project rather than default tasks of root project?


(Andy Hui) #1

I setup a multi project build like this:

rootProject (defaultTasks taskA) - subProject1 (defaultTasks taskB) - subProject2 (defaultTasks taskC)

I want to run all default tasks of all projects in one go. How can I do that?

Many Thanks.


Running Tasks on Subprojects
(Peter Niederwieser) #2

It depends on the Gradle startup directory. If you execute ‘gradle’ from the root project dir, it will run ‘taskA’. If you execute if from subproject1’s dir, it will run ‘taskB’. And so on.


(Andy Hui) #3

Yes I got that, but that’s not what I want. Is there a way to run all different default (or any way to define) tasks for different projects if I just startup gradle in the root?


(Peter Niederwieser) #4

You’d have to script ‘rootProject.defaultTasks’ to collect the ‘defaultTasks’ values of all subprojects.


(Gururaj R) #5

Any code snippet for this would be helpful.


(Gururaj R) #6

based on Peter’s suggestion, finally this code worked (may not be the best)

evaluationDependsOnChildren()
    /*subprojects {
        println name+" " + version
        println defaultTasks
        //dependsOn subproject.defaultTasks
}*/
    task runDefaultTasks {
        subprojects.each { subproject ->
                //println subproject.path
                subproject.defaultTasks.each {
                        dependsOn subproject.path+":"+it
                }
        }
}
  defaultTasks 'runDefaultTasks'