How to check Ant version inside Ant script

Here's a code snip that may help:

<property name="version.required" value="1.8" />

<target name="version_check">
    <antversion property="version.running" />
    <fail message="FATAL ERROR:  The running Ant version, ${version.running}, is too old.">
        <condition>
            <not>
                <antversion atleast="${version.required}" />
            </not>
        </condition>
    </fail>
</target>

<target name="doit" depends="version_check">
    <echo level="info" message="The running version of ant, ${version.running}, is new enough" />
</target>


Ant has built-in property ant.version:

<project default="print-version">
    <target name="print-version">
        <echo>${ant.version}</echo>
    </target>
</project>

No need to create a target, you can use fail+antversion at the beginning of your script :

<fail message="Ant 1.8+ required">
     <condition>
         <not><antversion atleast="1.8" /></not>
     </condition>
</fail>

Tags:

Java

Ant