Ant中的条件连接

时间:2012-06-10 14:44:56

标签: ant build.xml

我的任务如下:

<target name="someTarget">
    <concat destfile="someFile">
        <string>someString</string>

        <string>someOtherString</string>
    </concat>
</target>

<target name="someOtherTarget">
    <antcall target="someTarget">
        <param name="myParam" value="myValue"></param>
    </antcall>

    <antcall target="someTarget">
    </antcall>
</target>

如果在调用someOtherString目标时提供myParam,我如何连接someTarget

1 个答案:

答案 0 :(得分:4)

如果没有Ant扩展,只需使用conditional Ant execution

<project default="someOtherTarget">
    <target name="someTarget" depends="-someString,-someOtherString"/>

    <target name="-someString" unless="myParam">
        <concat destfile="someFile">
            <string>someString</string>
        </concat>
    </target>

    <target name="-someOtherString" if="myParam">
        <concat destfile="someOtherFile">
            <string>someString</string>
            <string>someOtherString</string>
        </concat>
    </target>

    <target name="someOtherTarget">
        <antcall target="someTarget">
            <param name="myParam" value="myValue"></param>
        </antcall>
        <antcall target="someTarget"/>
    </target>
</project>

如果您不介意在项目中添加Ant扩展程序,请查看Ant-ContribIf task