如何多次执行ant任务?

时间:2010-03-09 19:56:40

标签: ant build-automation

想象一下这是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

换句话说,我希望每个依赖项都能运行,无论它是否已经运行过。

1 个答案:

答案 0 :(得分: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