代码之家  ›  专栏  ›  技术社区  ›  Geo

我怎样才能不止一次地执行一个ant任务?

  •  3
  • Geo  · 技术社区  · 15 年前

    假设这是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 回复  |  直到 14 年前
        1
  •  4
  •   martin clayton egrunin    14 年前

    依赖关系不是为了这个。

    如果你需要这种行为,使用 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
    
    推荐文章