2010-03-09 51 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