How to define gradle task dependencies - inputs outputs OR dependsOn?

Viewed 978

To get the incremental build support running correctly in gradle it is required to define the "inputs" and "outputs" in each (custom-) tasks.

That's a very neat way of gradle to check if a task can be skipped cause it is up-to-date or not. Sample:

task myTaskA { 
   def someOutputDir = file("$buildDir/gen")

   // define task outputs (input not required here)
   outputs.dir someOutputDir

   doLast{
      // generate something into the defined output directory
      new File(someOutputDir, "dummy.txt").text = "Gradle sample" 
   }
}

task myTaskB {
   // Input of this task is dependent on the output of myTaskA
   inputs.files myTaskA

   doLast{
      // do something
   }
}

Yes, that is pretty nice and additionally the good thing is, we do not need to declare a explicit dependency instruction (dependsOn) in task "myTaskB".

dependsOn myTaskA 

This directive is not necessary cause we have a implicit dependency defined by the inputs-declaration.

I think it is a good style to provide always a inputs/outputs definition in custom tasks to support incremental builds.

BUT: This also means we can completely ignore the dependsOn.

SO: When should we prefer dependsOn over inputs/outputs?

Maybe if there is no inputs or outputs. Yes, but are there other use cases conceivable? I was always working with dependsOn, and this seams to me as obsolete now. What do you think?

Bye have a great day, Tony

0 Answers
Related