运行 特定条件下的 Ant 目标

Running an Ant target under certain conditions

我的 project.xml 中有以下 Ant 目标:

<target name="to.run.under.conditions"> 
</target> 

<target name="deploy1"> 
    <antcall target="deploy2"/>
</target>

<target name="deploy2">
    <antcall target="to.run.under.conditions"/>
</target>

<target name="another.target">
    <antcall target="deploy1"/>
</target>

我的意图是能够在运行宁another.target时排除目标to.run.under.conditions。我对 ANT 不是很熟悉,我正在努力了解如何解决这个问题。我尝试在 </code> 中使用 <code>unless="${target.running}" 并在 target name ="target.running"

中的条件任务中将 属性 设置为 true

你能帮忙吗?

感谢您的帮助,

我。

----编辑更新的解决方案----

这是我目前的尝试(我使用的是 ANT 1.8.2):

<target name="to.run.under.conditions" if="${target.running}"> 
</target>

<target name="another.target">
<property name="target.running" value="false"/> 
</target>

如果我没记错的话,因为another.target里面的属性设置为false,那么to.run.under.conditions不应该是运行(我可能是错的,虽然).是否有意义?非常感谢任何评论!

试试这个:

<target name="build-module-A" if="module-A-present"/>
<target name="build-own-fake-module-A" unless="module-A-present"/>

在第一个示例中,如果设置了 module-A-present 属性(设置为任何值,例如 false),则目标将为 运行。在第二个示例中,如果设置了 module-A-present 属性(再次设置为任何值),目标将不会是 运行。

请参阅Any Targets了解更多信息。

我最终得到了这个似乎按预期工作的解决方案:

<target name="deploy2">
    <if>
        <equals arg1="${target.running}" arg2="true" />
        <then>
            <echo message="the target will not run" />
        </then>
        <else>
            <echo message="the target will run" />
                <antcall target="to.run.under.conditions"/>
        </else>
    </if>   
  </target>

    <target name="to.run.under.conditions"> 
    </target>

    <target name="another.target">
    <property name="target.running" value="true"/>  
    </target>

希望对您有所帮助,

我。