即使 Ant 任务失败,Ant 也会成功 [英] Ant Successful even when Ant Task fails

查看:37
本文介绍了即使 Ant 任务失败,Ant 也会成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一定是我遗漏了一个简单的设置,所以请原谅我,但我曾两次注意到我的错误 ant 任务不会导致构建失败.例如:

There must be a simple setting I am missing so forgive me, but I've noticed on two occasions that my bad ant tasks do not cause the build to fail. For example:

  1. 当源文件不存在时的 Ant 复制......构建成功

  1. Ant copy when source file does not exist ... BUILD SUCCESSFUL

Ant 解压,当任务报告无法写入文件"或类似消息时...构建成功

Ant unzip, when task reports "can't write file" or similar message ... BUILD SUCCESSFUL

Ant exec 错误,无效的语法...构建成功

Ant exec error, invalid syntax ... BUILD SUCCESSFUL

我如何保证所有 ant 任务错误都会导致构建失败?

推荐答案

  • 任务默认不会失败.您需要使用 failonerror="true"

    • <EXEC> tasks do no fail by default. You need to enable this with failonerror="true"

      Ant 任务的失败取决于所使用的资源集合类型.如果您使用 filesetpatternset,则所有丢失的文件都会静默忽略.您只能通过使用 filelist 类型或使用参数化的 'file` 属性来强制失败.

      Failure of the Ant <COPY> task depends on what resource collection type is used. If you use a fileset or patternset, then all missing files are silently ignored. You can force a failure only by using the filelist type or the parameterized 'file` attribute is used.

      因此,您要使用的是:

      <copy todir="my_dir" file="foo" />
      
      <copy todir="my_dir" flatten="true">
        <filelist dir="" files="foo" />
      </copy>
      
      <copy todir="my_dir" flatten="true">
        <filelist dir="">
           <file name="foo" />
           <file name="bar" />
           <file name="zed" />
        </filelist>
      </copy>
      

    • 这篇关于即使 Ant 任务失败,Ant 也会成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆