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

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.

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.

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?

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

Any code snippet for this would be helpful.

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

    /*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'