Oh OK I will try that. Incidentally, I have managed to accomplish the desired 
effect from the "other direction" by using an onlyIf closure. Is one preferred 
over the other?

I will post new questions to the forum. Is this mailing list deprecated? Can 
you help me distinguish which messages go here vs. the forum?

Thanks.


From: Rene Groeschke <[email protected]<mailto:[email protected]>>
Reply-To: "[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Date: Tue, 10 Apr 2012 13:39:51 -0500
To: "[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Subject: Re: [gradle-user] Conditional Task Dependency

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é

[cid:[email protected]]
Neil Chaudhuri<mailto:[email protected]>
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.


________________________________

<<inline: compose-unknown-contact.jpg>>

Reply via email to