[GRADLE-1626] Task dependency fail for external scripts Created: 20/Jun/11  Updated: 04/Jan/13  Resolved: 21/Jun/11

Status: Resolved
Project: Gradle
Affects Version/s: 0.9.2
Fix Version/s: None

Type: Bug
Reporter: Max Garmash Assignee: Unassigned
Resolution: Won't Fix Votes: 0


 Description   

---build.gradle---
task testExt <<

{ apply from: 'external.gradle' project.taskX.execute() }

--------------------

-external.gradle-
task taskX(dependsOn: 'taskY') <<

{ println 'taskX' }

task taskY <<

{ println 'taskY' }

-------------------

Results:

gradle -b ./test.gradle testExt
:buildSrc:compileJava UP-TO-DATE
:buildSrc:compileGroovy UP-TO-DATE
:buildSrc:processResources UP-TO-DATE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestJava UP-TO-DATE
:buildSrc:compileTestGroovy UP-TO-DATE
:buildSrc:processTestResources UP-TO-DATE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test UP-TO-DATE
:buildSrc:check UP-TO-DATE
:buildSrc:build UP-TO-DATE
:buildSrc:compileJava UP-TO-DATE
:buildSrc:compileGroovy UP-TO-DATE
:buildSrc:processResources UP-TO-DATE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestJava UP-TO-DATE
:buildSrc:compileTestGroovy UP-TO-DATE
:buildSrc:processTestResources UP-TO-DATE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test UP-TO-DATE
:buildSrc:check UP-TO-DATE
:buildSrc:build UP-TO-DATE
:testExt
taskX

BUILD SUCCESSFUL

Total time: 5.654 secs

------------------------------

gradle -b ./test.gradle taskX
:buildSrc:compileJava UP-TO-DATE
:buildSrc:compileGroovy UP-TO-DATE
:buildSrc:processResources UP-TO-DATE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestJava UP-TO-DATE
:buildSrc:compileTestGroovy UP-TO-DATE
:buildSrc:processTestResources UP-TO-DATE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test UP-TO-DATE
:buildSrc:check UP-TO-DATE
:buildSrc:build UP-TO-DATE
:buildSrc:compileJava UP-TO-DATE
:buildSrc:compileGroovy UP-TO-DATE
:buildSrc:processResources UP-TO-DATE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestJava UP-TO-DATE
:buildSrc:compileTestGroovy UP-TO-DATE
:buildSrc:processTestResources UP-TO-DATE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test UP-TO-DATE
:buildSrc:check UP-TO-DATE
:buildSrc:build UP-TO-DATE
:taskY
taskY
:taskX
taskX

BUILD SUCCESSFUL



 Comments   
Comment by Szczepan Faber [ 21/Jun/11 ]

Hey,

task.execute() method only executes the 'actions' associated with the task. Actions are attached to task for example via .doLast {} or shorthand notation << {}. task.execute() bypasses task graph calculation, resolving task dependencies, etc. So by design, the task.execute() does not consider task dependencies.

Basically, executing tasks in an imperative fashion is against the spirit of gradle. Check out the mailing list about threads on that matter (e.g. task order, executing tasks explicitly).

The correct way of solving your problem should be:

task testExt {
  apply from: 'external.gradle'
  dependsOn taskX
}

Hope that helps!

Generated at Wed Jun 30 12:00:22 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.