cmcginty
cmcginty

Reputation: 117018

Ant Successful even when Ant Task fails

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?

Upvotes: 12

Views: 12532

Answers (2)

cmcginty
cmcginty

Reputation: 117018

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

Upvotes: 10

Bharat Sinha
Bharat Sinha

Reputation: 14363

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>

Upvotes: 5

Related Questions