即使在 java 错误之后 Ant 构建成功,如何让它失败?

Ant build success even after an java error, how to make it fail?

Ant 即使在 return 1 上也取得了成功:-

     [java] Error: Main method not found in class org.gaurav.learnjava.Calculator, please define the main method as:
     [java]    public static void main(String[] args)
     [java] or a JavaFX application class must extend javafx.application.Application
     [java] Java Result: 1

https://gitlab.com/gaurav1999/learnfosswithjava/-/jobs/238286189

<property name="src.dir"     value="src"/>

<property name="build.dir"   value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir"     value="${build.dir}/jar"/>

<property name="main-class"  value="org.gaurav.learnjava.Calculator"/>



<target name="clean">
    <delete dir="${build.dir}"/>
</target>

<target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${src.dir}" destdir="${classes.dir}"/>
</target>

<target name="jar" depends="compile">
    <mkdir dir="${jar.dir}"/>
    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
        <manifest>
            <attribute name="Main-Class" value="${main-class}"/>
        </manifest>
    </jar>
</target>

<target name="run" depends="jar">
    <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>

<target name="clean-build" depends="clean,jar"/>

<target name="main" depends="clean,run"/>

如果出现 [java] 错误,构建失败会很好。

<java jar="${jar.dir}/${ant.project.name}.jar" fork="true" failonerror="true"/>