如何多次执行Ant任务?

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>

What do I need to do so that when I run:

ant third

我将会收到以下输出:
first,first,second,third

换句话说,我希望每个依赖项都能运行,无论它以前是否运行过。
1个回答

4

依赖关系不是用来做这个的。

如果需要这种行为,请使用antcall或者MacroDef

<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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接