0

我有这个 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”任务或“目标”集成。

其他方向是“for”的“failonany”属性,但我没有明确设置它。

可以请教...

谢谢。

4

1 回答 1

0

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

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

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

<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>
于 2018-03-06T23:58:29.297 回答