Arun
Arun

Reputation: 3680

Gradle dependsOn not working when called again within dependent task

I wanted to run superParent task in my below build.gradle whenever it is called.

task superParent {
    doLast {
        println 'Hello Super Parent Last'
    }
}

task helloParent {
    dependsOn superParent
    description 'Hello task is Dependent on helloParent Task'
    doFirst {
        println 'Hello Parent First'
    }
    doLast {
        println 'Hello Parent Last'
    }
}

task hello {
    description 'Just prints Hello..'
    dependsOn helloParent,superParent
    doFirst {
        println 'Hello First'
    }
    doLast {
        println 'Hello Last'
    }
}

when i execute gradlew hello, am getting the below output

> Task :superParent       
Hello Super Parent Last   

> Task :helloParent       
Hello Parent First        
Hello Parent Last         

> Task :hello             
Hello First               
Hello Last  

The superParent task is not called again from the hello task. I am expecting an output like this

Expected Outcome

> Task :superParent       
Hello Super Parent Last   

> Task :helloParent       
Hello Parent First        
Hello Parent Last     

> Task :superParent       
Hello Super Parent Last     

> Task :hello             
Hello First               
Hello Last   

Upvotes: 1

Views: 1120

Answers (1)

Opal
Opal

Reputation: 84786

There's no option to add a task to a DAG (directed acyclic graph - which gradle uses under the hood) more than once. A task may be added at most once. Hence, if you define a dependency from task A and B to C the order of execution might be:

  • C -> B -> A
  • C -> A -> B

But C will be run only once.

Upvotes: 2

Related Questions