即使 Ant 任务失败,Ant 也会成功

即使 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>