Sumeet Jindal
Sumeet Jindal

Reputation: 902

How to check Ant version inside Ant script

My ant script only works with version >=1.8. I want to check the version in the script, so that it displays error if a lesser version installed.

Upvotes: 19

Views: 15590

Answers (6)

Rostislav V
Rostislav V

Reputation: 1798

In terminal type, just execute:

ant -version

Upvotes: 0

isapir
isapir

Reputation: 23483

Add the following at the beginning of your build script:

<!-- Check Ant Version -->
<property name="ant.version.required"       value="1.9.8" />

<fail message="Ant version ${ant.version.required} or newer is required 
      (${ant.version} is installed)">
  <condition>
    <not><antversion atleast="${ant.version.required}" /></not>
  </condition>
</fail>

If the Ant version is lower than required, it will produce an error like this:

Ant version 1.9.8 or newer is required (Apache Ant(TM) version 1.9.7 compiled on April 9 2016 is installed)

Upvotes: 0

user1075613
user1075613

Reputation: 745

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>

Upvotes: 9

Cyril Sagan
Cyril Sagan

Reputation: 121

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>

Upvotes: 12

Mark O&#39;Connor
Mark O&#39;Connor

Reputation: 77951

Version 1.7 of ANT introduced a dedicated antversion task.

This functionality is part of several conditions that can be checked by ANT.

Upvotes: 5

Victor Sorokin
Victor Sorokin

Reputation: 11996

Ant has built-in property ant.version:

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

Upvotes: 7

Related Questions