Can Ant continue when it encounters an error?

2019-05-04 22:04发布

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?

标签: ant
2条回答
Root(大扎)
2楼-- · 2019-05-04 22:25

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.

查看更多
做自己的国王
3楼-- · 2019-05-04 22:32

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.

查看更多
登录 后发表回答