问题
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.
回答1:
Ant has built-in property ant.version
:
<project default="print-version">
<target name="print-version">
<echo>${ant.version}</echo>
</target>
</project>
回答2:
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>
回答3:
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>
回答4:
Version 1.7 of ANT introduced a dedicated antversion task.
This functionality is part of several conditions that can be checked by ANT.
回答5:
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)
回答6:
In terminal type, just execute:
ant -version
来源:https://stackoverflow.com/questions/10514222/how-to-check-ant-version-inside-ant-script