2010-10-25 47 views

回答

19

是的,依赖项在条件得到评估之前执行。


Ant manual

重要: if和除非属性仅启用或禁用目标它们所连接到。它们不控制目标是否依赖于条件目标执行。事实上,他们甚至在目标即将被执行之前都不会被评估,并且其所有前任都已经运行。


你也可以尝试一下自己:

<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在执行后执行所以depend被评估为之前if(使用Ant 1.7.0)。

4

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 
+3

这不是一个答案,这是问的问题。 – 2015-06-11 12:48:22