Hello Neil,
a dependsOn declaration in a doFirst closure has no effect, because the doFirst closure is executed, when the task graph is already created and gradle executes each task in that directed graph. try
-------------------
bar{
  def aFile = file("/path/to/file")
  if (!aFile.exists()) {
    println "Doesn't exist"
    dependsOn foo
  }
}
 

-------------------
instead. BTW.: the gradle forum (http://forums.gradle.org/gradle) is a much better place for this kind of question.

regards,
René

10. April 2012 19:23
I would like for one task to be dependent on another conditionally. The way I have tried this is as follows:

task foo {
  //Do stuff
}

task bar << {
  //do other stuff
}

bar.doFirst {
  def aFile = file("/path/to/file")
  if (!aFile.exists()) {
    println "Doesn't exist"
    dependsOn foo
  }
}

Unfortunately, even though executing bar produces the "Doesn't exist" statement, foo doesn't execute before  bar. It doesn't execute at all.

Any insight into how I can enable conditional task dependencies is appreciated.

Thanks.




Reply via email to