Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant Successful even when Ant Task fails

Tags:

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

like image 890
cmcginty Avatar asked Sep 21 '12 02:09

cmcginty


2 Answers

  • <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>
    
like image 120
cmcginty Avatar answered Sep 27 '22 21:09

cmcginty


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>
like image 29
Bharat Sinha Avatar answered Sep 27 '22 21:09

Bharat Sinha