Som Sarkar Som Sarkar - 3 months ago 18
Java Question

Failing a ant build if the Java version is 1.5 or 1.6

I have an ant build file, which first checks what is the version of JAVA in my system. the code is like this-

<target name="-private.check.java">
<echo message="Ant java version: ${ant.java.version}" />
</target>


The output is -

-private.check.java:
[echo] Ant java version: 1.7


Now I want to make Build Fail if the java version is less than 1.7, how can I do that?

Answer
<target name="checkJava">
    <fail message="Unsupported Java version: ${java.version}. Make sure that the Java version is 1.7.">
        <condition>
            <not>
                <or>
                    <contains string="${java.version}" substring="1.7" casesensitive="false" /> 
                    <contains string="${java.version}" substring="1.8" casesensitive="false" /> 
                </or>
            </not>
        </condition>
    </fail>
</target>