Different task execution order

I have simple multiproject build with one parent and one child (called subproject).

If I configure the child project in parent’s build.gradle:

dependsOnChildren()
apply plugin: 'java'
  project(':subproject') {
  apply plugin: 'java'
}

the tasks are exucuted in this order:

$ gradle classes
:sub:compileJava UP-TO-DATE
:compileJava UP-TO-DATE
:sub:processResources UP-TO-DATE
:processResources UP-TO-DATE
:sub:classes UP-TO-DATE
:classes UP-TO-DATE
BUILD SUCCESSFUL

But when I configure it in subproject/build.gradle

## build.gradle
dependsOnChildren()
apply plugin: 'java'
  ## subproject/build.gradle
apply plugin: 'java'

the tasks are executed in different order:

$ gradle classes
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:sub:compileJava UP-TO-DATE
:sub:processResources UP-TO-DATE
:sub:classes UP-TO-DATE
BUILD SUCCESSFUL

Why is the task exucution order different? I’ve read throught all the documentation, but haven’t found an answer for this behaviour. I checked it with gradle 1.0-milestone-3, 6 and 7

Thanks a lot, Pavel

dependsOnChildren() is executed against the current project. So, if you configure that in your subproject you’re making the subproject depending on its children. It’s different than configuring the root project to depend on its children.

dependsOnChildren() is the same as: project.dependsOnChildren() The project is different depending where the configuration lives (e.g. which build.gradle, etc.)

Hope that helps!

Hi, thanks for quick answer. Maybe you overlooked it, but in code samples I sent, the dependsOnChildren() is always in parent project - even in the second sample (there are comments with filename).

I think it’s a bug. A workaround is to put this at the very end of the parent build script, replacing an earlier ‘dependsOnChildren()’:

dependsOnChildren(true)

dependsOnChildren(true) works fine. Thanks.