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" />
Yes, the dependencies are executed before the conditions get evaluated.
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.
Here is an example:
<project>
<target name="-runTests">
<property name="testSetupDone" value="foo"/>
</target>
<target name="runTestsIfTestSetupDone" if="testSetupDone" depends="-runTests">
<echo>Test</echo>
</target>
</project>
The property testSetupDone
is set within the target in depends
, 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. runTestsIfTestSetupDone
is executed afterwards, so depend
is evaluated before if
.
From the docs:
Ant tries to execute the targets in the depends attribute in the order they
appear (from left to right). Keep in mind that it is possible that a
target can get executed earlier when an earlier target depends on it:
<target name="A"/>
<target name="B" depends="A"/>
<target name="C" depends="B"/>
<target name="D" depends="C,B,A"/>
Suppose we want to execute target D. From its depends attribute,
you might think that first target C, then B and then A is executed.
Wrong! C depends on B, and B depends on A,
so first A is executed, then B, then C, and finally D.
Call-Graph: A --> B --> C --> D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With