【问题标题】:how to ignore a failure ant task?如何忽略失败的蚂蚁任务?
【发布时间】:2018-03-03 19:11:58
【问题描述】:

我有这个 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”属性,但我没有明确设置它。

你能不能给点建议...

谢谢。

【问题讨论】:

    标签: ant ant-contrib failonerror


    【解决方案1】:

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

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

    不要使用 ant-contrib 的 &lt;if&gt; 块,而是使用标准的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-29
      • 2013-12-04
      相关资源
      最近更新 更多