Ant Successful even when Ant Task fails

可紊 提交于 2019-12-10 12:37:50

问题


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 copy when source file does not exist ... BUILD SUCCESSFUL

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

  3. Ant exec error, invalid syntax ... BUILD SUCCESSFUL

How do I guarantee all ant task errors will result in a build failure?


回答1:


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

  • 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.

    Therefore what you want to use is either:

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



回答2:


Have you tried following:

<copy todir="your/path/details" failonerror="true">
</copy>

<zip destfile="your/path/details" whenempty="fail">
</zip>

<exec executable="your/path/details" failonerror="true">
</exec>


来源:https://stackoverflow.com/questions/12523430/ant-successful-even-when-ant-task-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!