如何忽略失败的蚂蚁任务?

how to ignore a failure ant task?

我有这个 ant 脚本,它从参数中读取组件列表和 运行 其他 ant 任务(build.xml):

<for list="${components.locations}" param="component" failonany="false">
                <sequential>
                    <property name="@{component}" value="true"/>
                    <if>
                        <and>
                            <available file="${repository.location}/@{component}"/>
                            <available file="${repository.location}/${jars.location}"/>
                        </and>
                        <then>
                            <ant inheritAll="false" antfile="${repository.location}/@{component}/build.xml">
                                <!-- failonerror="false" -->
                                <property name="copy.libs" value="${copy.libs}"/>
                                <property name="repository.location" value="${repository.location}"/>
                                <property name="jars.location" value="${repository.location}/${jars.location}"/>
                            </ant>
                        </then>
                    </if>
                </sequential>
            </for>

问题是如果一个组件出现故障,脚本不会继续到下一个组件。

我尝试了 运行 -k (-keep-going) 参数,但没有用。 我发现这个 属性 failonerror="false" 但它对 "exec" 任务有效并且无法将它与 "ant" 任务集成或在 "target".[=11 中=]

其他方向是 "for" 的 "failonany" 属性,但我没能明确地设置它。

能否请您指教...

谢谢。

首先,我建议删除 ant-contrib.jar 并且永远不要回头。相信我,你会帮自己一个忙。

您可以使用 subant 任务在一组目录或文件上迭代 Ant 构建。只需定义一个 dirset 并传递您需要的任何额外属性。

不使用 ant-contrib 的 <if> 块,而是使用标准 targetif 属性来打开或关闭整个目标。这是更安全和更好的做法。

<property name="repository.location" location="repository_location" />
<property name="jars.location" location="${repository.location}/jars" />
<property name="components" value="dir1,dir2,dir3" />

<target name="init">
    <condition property="jars.available">
        <available file="${jars.location}" />
    </condition>
</target>

<target name="default" depends="init" if="jars.available">
    <subant inheritall="false" failonerror="false">
        <dirset id="components.dirs" dir="${repository.location}" includes="${components}" />
        <property name="copy.libs" value="${copy.libs}" />
        <property name="repository.location" value="${repository.location}" />
        <property name="jars.location" value="${jars.location}" />
    </subant>
</target>