2010-03-09 73 views
3

想象一下從build.xml文件中的代碼:如何多次執行一個螞蟻任務?

<project name="test project"> 
    <target name="first"> 
     <echo>first</echo> 
    </target> 
    <target name="second" depends="first"> 
     <echo>second</echo> 
    </target> 
    <target name="third" depends="first,second"> 
     <echo>third</echo> 
    </target> 
</project> 

什麼我需要做的,這樣,當我運行:

ant third 

我會收到以下輸出:

first,first,second,third 

換句話說,我希望每個依賴運行,而不管它是否已經運行過。

回答

4

這不是什麼依賴關係。

如果您需要該行爲,請改爲使用antcallMacroDef

<project name="test project"> 
    <target name="first"> 
     <echo>first</echo> 
    </target> 
    <target name="second"> 
     <antcall target="first" /> 
     <echo>second</echo> 
    </target> 
    <target name="third"> 
     <antcall target="first" /> 
     <antcall target="second" /> 
     <echo>third</echo> 
    </target> 
</project> 

> ant third 
Buildfile: build.xml 

third: 

first: 
    [echo] first 

second: 

first: 
    [echo] first 
    [echo] second 
    [echo] third 

BUILD SUCCESSFUL 
Total time: 0 seconds