Can Ant continue when it encounters an error?

2019-05-04 22:10发布

问题:

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?

回答1:

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.



回答2:

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.



标签: ant