2010-10-25 86 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