tags:

views:

55

answers:

1

That is, will calling the following target when testSetupDone evaluates to false, execute the targets in dependency chain?

<target name="-runTestsIfTestSetupDone" if="testSetupDone" depends="-runTests" />
+2  A: 

From the Ant manual:

Important: the if and unless attributes only enable or disable the target to which they are attached. They do not control whether or not targets that a conditional target depends upon get executed. In fact, they do not even get evaluated until the target is about to be executed, and all its predecessors have already run.


You could also have tried yourself:

<project>
  <target name="-runTests">
    <property name="testSetupDone" value="foo"/>
  </target>
  <target name="runTestsIfTestSetupDone" if="testSetupDone" depends="-runTests">
    <echo>Test</echo>
  </target>
</project>

I'm setting the property testSetupDone within the depending target, and the output is:

Buildfile: build.xml

-runTests:

runTestsIfTestSetupDone:
     [echo] Test

BUILD SUCCESSFUL
Total time: 0 seconds

Target -runTests is executed, even though testSetupDone is not set at this moment, and runTestsIfTestSetupDone is executed afterwards, so depend is evaluated before if (using Ant 1.7.0).

Peter Lang
To add to your answer, from the FAQ at http://ant.apache.org/manual/targets.html
JoseK
Important: the if and unless attributes only enable or disable the target to which they are attached. *They do not control whether or not targets that a conditional target depends upon get executed. In fact, they do not even get evaluated until the target is about to be executed, and all its predecessors have already run.*
JoseK
@JoseK: I edited that into my answer, thanks a lot!
Peter Lang