0

I'm trying to make an Ant target that runs if ONE of two other targets completes. Basically, assuming I have three targets A1, A2, and B, I want B to run only if A1 OR A2 run. A1 and A2 depend on a condition, so either A1 or A2 will run (but never both).

For example:

<target name="A1" if="${conditionalVar}"> 
<target name="A2" unless="${conditionalVar}">
<target name="B" depends="????????">

What should the 'depends' for target B be? Is there anyway to do this?

pghprogrammer4
  • 898
  • 2
  • 9
  • 21

1 Answers1

3

Yes, such a configuration is possible and not very complicated:

The trick is to set a property that will be tested if set (e.g. call it "taskA1.use").

<target name="A1" if="taskA1.use" />
<target name="A2" unless="taskA1.use" />
<target name="B" depends="A1,A2" />

Therefore even if B depends on both tasks A1 and A2 only one will be executed depending of the property "taskA1.use" has been set or not.

Robert
  • 39,162
  • 17
  • 99
  • 152
  • But B depends on both A1 and A2, so wouldn't both have to run in order for B to occur? Or would A2 "count" as being run even if taskA1.use is set and therefore A2 doesn't run all its code? – pghprogrammer4 Dec 21 '11 at 16:04
  • The condition is evaluated before the target is run. So if `taskA1.use` is not set, then A1 would not execute and not "count as being run". – barfuin Dec 21 '11 at 21:16
  • Both A1, A2 targets are invoked, only one is actually executed due to the property conditions. – Mark O'Connor Dec 21 '11 at 21:17