如何多次执行 Ant 任务?

发布于 2024-08-25 01:11:44 字数 587 浏览 6 评论 0原文

将其想象为 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

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

Imagine this as the code from 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

I would receive the following output:

first,first,second,third

In other words, I would like each dependency to run regardless of whether it has ran before or not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云巢 2024-09-01 01:11:44

这不是依赖关系的用途。

如果您需要这种行为,请使用 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

That's not what dependencies are for.

If you need that behavior, use antcall or MacroDef instead.

<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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文