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

**URL:** <https://discuss.gradle.org/t/gradle-2-10-tasks-execute-ignores-java-plugin-tasks-like-clean-assemble/13951>\
**Category:** Help/Discuss\
**Created:** [January 22, 2016, 10:53pm UTC](https://discuss.gradle.org/t/gradle-2-10-tasks-execute-ignores-java-plugin-tasks-like-clean-assemble/13951 "2016-01-22T22:53:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zak](https://avatars.discourse-cdn.com/v4/letter/z/8e7dd6/32.png) [@zak](https://discuss.gradle.org/u/zak)\
**Post date:** [January 22, 2016, 10:53pm UTC](https://discuss.gradle.org/t/gradle-2-10-tasks-execute-ignores-java-plugin-tasks-like-clean-assemble/13951/1 "2016-01-22T22:53:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [January 23, 2016, 7:29am UTC](https://discuss.gradle.org/t/gradle-2-10-tasks-execute-ignores-java-plugin-tasks-like-clean-assemble/13951/2 "2016-01-23T07:29:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zak](https://avatars.discourse-cdn.com/v4/letter/z/8e7dd6/32.png) [@zak](https://discuss.gradle.org/u/zak)\
**Post date:** [January 25, 2016, 3:58pm UTC](https://discuss.gradle.org/t/gradle-2-10-tasks-execute-ignores-java-plugin-tasks-like-clean-assemble/13951/3 "2016-01-25T15:58:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [January 25, 2016, 4:14pm UTC](https://discuss.gradle.org/t/gradle-2-10-tasks-execute-ignores-java-plugin-tasks-like-clean-assemble/13951/4 "2016-01-25T16:14:59Z")

</div>

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.”

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [January 25, 2016, 4:20pm UTC](https://discuss.gradle.org/t/gradle-2-10-tasks-execute-ignores-java-plugin-tasks-like-clean-assemble/13951/5 "2016-01-25T16:20:28Z")

</div>

See task dependencies and ordering [here](https://docs.gradle.org/current/dsl/org.gradle.api.Task.html#N16A38)

---

<div class="post-metadata">

**Author:** ![zak](https://avatars.discourse-cdn.com/v4/letter/z/8e7dd6/32.png) [@zak](https://discuss.gradle.org/u/zak)\
**Post date:** [January 25, 2016, 4:27pm UTC](https://discuss.gradle.org/t/gradle-2-10-tasks-execute-ignores-java-plugin-tasks-like-clean-assemble/13951/6 "2016-01-25T16:27:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zak](https://avatars.discourse-cdn.com/v4/letter/z/8e7dd6/32.png) [@zak](https://discuss.gradle.org/u/zak)\
**Post date:** [January 25, 2016, 6:10pm UTC](https://discuss.gradle.org/t/gradle-2-10-tasks-execute-ignores-java-plugin-tasks-like-clean-assemble/13951/7 "2016-01-25T18:10:41Z")

</div>

will do  
thank you Lance
