Please excuse if the question is dumb, I’m only 2nd day on Ant and Java hacking together some CI solution with next to no knowledge of Ant or Java.
So I wish a build to fail if (my) java program run as a step within the build decides that the build must fail.
I thought of just throwing an unhandled exception in the Java program or using System.exit() to shut down the JVM but they seem quite nasty.
Is there a nice way of ant failing the build if a java step decides it should?
For the
<java>task, there is an attributefailonerror. If you set it toyes(ortrue), the build will fail if the process returned anything else than 0.The problem is that for returning some value from a java call, this call must
System.exit(value). For it to not kill your ant, you also need to providefork=trueto run in a new JVM.So, the java call could look like this:
Of course, you could also have your Java program implement the Ant Task API and load/call it as a proper ant task. Then it can itself decide what to do (and will be more configurable, too).