John W
John W

Reputation: 610

Can Ant continue when it encounters an error?

I have an Ant target that executes 2 steps in sequence:

<target name="release">
    <antcall target="-compile"/>
    <antcall target="-post-compile"/>
</target>

With the above script, it quits immediately if the "-compile" target fails. "-post-compile" does not get a chance to run. Is there a way to make sure the second step (-post-compile) is executed even if the 1st one (-compile) fails?

Upvotes: 5

Views: 4178

Answers (2)

barfuin
barfuin

Reputation: 17474

If you are using ant-contrib (which is very common), you could make use of the try-catch task and put your post-compile call into its finally element.

Also, if you are not using ant-contrib, then you might use the subant task to call your compile target. subant has a failonerror attribute, which you can use to individually ignore failed targets. Lots of usage examples on the task description page.

Upvotes: 3

Neo
Neo

Reputation: 1554

I think you are looking for

-keep-going (-k)

This will tell Ant to continue building all targets which do not depend on the failed target.

Upvotes: 2

Related Questions