也就是说,当testSetupDone求值为false时会调用以下目标,在依赖链中执行目标吗?
<target name="-runTestsIfTestSetupDone" if="testSetupDone" depends="-runTests" />
答案 0 :(得分:20)
是的,在评估条件之前执行依赖项。
来自Ant manual:
重要提示: if和unless属性仅启用或禁用它们所附加的目标。它们不控制条件目标所依赖的目标是否被执行。实际上,在目标即将执行之前,它们甚至都没有得到评估,并且它的所有前辈都已经运行了。
您也可以尝试自己:
<project>
<target name="-runTests">
<property name="testSetupDone" value="foo"/>
</target>
<target name="runTestsIfTestSetupDone" if="testSetupDone" depends="-runTests">
<echo>Test</echo>
</target>
</project>
我在依赖目标中设置属性testSetupDone
,输出为:
Buildfile: build.xml
-runTests:
runTestsIfTestSetupDone:
[echo] Test
BUILD SUCCESSFUL
Total time: 0 seconds
目标-runTests
已执行,即使此时未设置testSetupDone
,之后也会执行runTestsIfTestSetupDone
,因此{/ 1}}在之前进行评估 depend
(使用Ant 1.7.0)。
答案 1 :(得分:5)
来自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