Gradle 2.10: tasks.execute() ignores java plugin tasks like 'clean' 'assemble'

I have the following structure for my flat multi project build:
this is my root project:
neotip_root_gradle
…build.gradle
…settings.gradle

neotip_common
…build.gradle
neotip_data
…build.gradle
neotip_view
…build.gradle

[settings.gradle]
include “neotip_common”, “neotip_data”, "neotip_view"
project(’:neotip_common’).projectDir = new File(’…/neotip_common’)
project(’:neotip_data’).projectDir = new File(’…/neotip_data’)
project(’:neotip_view’).projectDir = new File(’…/neotip_view’)

=============================
neotip_root_gradle: build.gradle
//only a println

neotip_common: build.gradle
task buildALL << {
tasks.buildCOMMON.execute()
println “zCompleted ‘buildALL’ for $project”
}
assemble.mustRunAfter clean
task buildCOMMON (dependsOn: [‘clean’, ‘assemble’]) << {
println “zCompleted ‘buildCOMMON’ for $project”
}

neotip_data: build.gradle
task buildALL (dependsOn: ‘:neotip_common:buildALL’) << {
tasks.buildDATA.execute()
println “zCompleted ‘buildALL’ for $project”
}
assemble.mustRunAfter clean
task buildDATA (dependsOn: [‘clean’, ‘assemble’]) << {
println “zCompleted ‘buildDATA’ for $project”
}

neotip_view: build.gradle
task buildALL (dependsOn: ‘:neotip_data:buildALL’) << {
tasks.buildVIEW.execute()
println “zCompleted ‘buildALL’ for $project”
}
assemble.mustRunAfter clean
task buildVIEW (dependsOn: [‘clean’, ‘assemble’]) << {
println “zCompleted ‘buildVIEW’ for $project”
}

=============================
when I call buildall from the root project. it finds all sub projects but it ignores the java plugin tasks [clear, assemble].
C:…\neotip_root_gradle>gradlew buildall
:neotip_common:buildALL
zCompleted ‘buildCOMMON’ for project ':neotip_common’
zCompleted ‘buildALL’ for project ‘:neotip_common’
:neotip_data:buildALL
zCompleted ‘buildDATA’ for project ':neotip_data’
zCompleted ‘buildALL’ for project ‘:neotip_data’
:neotip_view:buildALL
zCompleted ‘buildVIEW’ for project ':neotip_view’
zCompleted ‘buildALL’ for project ‘:neotip_view’

BUILD SUCCESSFUL



but when I change the tasks to:

neotip_common: build.gradle
task buildALL (dependsOn: [‘clean’, ‘assemble’]) << {
println “zCompleted ‘buildALL’ for $project”
}

neotip_data: build.gradle
task buildALL (dependsOn: [’:neotip_common:buildALL’, ‘clean’, ‘assemble’]) << {
println “zCompleted ‘buildALL’ for $project”
}

neotip_view: build.gradle
task buildALL (dependsOn: [’:neotip_data:buildALL’, ‘clean’, ‘assemble’]) << {
println “zCompleted ‘buildALL’ for $project”
}

now, run it again
C:…\neotip_root_gradle>gradlew buildall

:neotip_common:clean
:neotip_common:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:neotip_common:processResources UP-TO-DATE
:neotip_common:classes
:neotip_common:jar
:neotip_common:assemble
:neotip_common:buildALL
zCompleted ‘buildALL’ for project ‘:neotip_common’
:neotip_data:clean
:neotip_data:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:neotip_data:processResources UP-TO-DATE
:neotip_data:classes
:neotip_data:jar
:neotip_data:assemble
:neotip_data:buildALL
zCompleted ‘buildALL’ for project ‘:neotip_data’
:neotip_view:clean
:neotip_view:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
47 warnings
:neotip_view:processResources UP-TO-DATE
:neotip_view:classes
:neotip_view:jar
:neotip_view:assemble
:neotip_view:buildALL
zCompleted ‘buildALL’ for project ‘:neotip_view’

BUILD SUCCESSFUL

works like a charm,
can any one explain to me why the tasks…execute() ignores the dependson for the java plugin tasks.
thank you very much

You should not be calling the execute() method on a Task directly. The method is for internal use only, which is why it’s defined in org.gradle.api.internal.AbstractTask.

When you call execute(), all dependencies of those tasks are being ignored, not just those in the java plugin. Calling execute() explicitly circumvents the steps Gradle would normally take to guarantee dependencies are met.

If you pay close attention to the output, you can see that the buildALL task on each project is the only one that is actually running due to matching the task name that you specified on the command line. You see the completed message because you called the method that called the task action methods, but as far as Gradle is concerned those other buildCOMMON, buildDATA, and buildVIEW tasks weren’t in the task graph, and didn’t actually run.

Thank you very much for clarifying this for me.
do you know what other command that I can use to accomplish this in my build (calling tasks from another task). in the mean time I’ll try and google it.
-Zak

Using dependsOn to model your task dependencies is the expected/supported way to run tasks (and other dependent tasks).

What’s wrong with your second version that does make use of the task dependencies? You said it “works like a charm.”

See task dependencies and ordering here

Hi James
oh, nothing wrong with the second version. as you can tell, I’m new to gradle and trying to understand it better.
we have an ant build.xml that uses tags like this:
taskA…
…call ant task1…
…call ant task2…
…call ant task3…
I was hoping that there is a way to do this in gradle.
in any case, I want to thank you again for being so helpful.
-Zak

will do
thank you Lance