我的Ant脚本只适用于版本大于等于1.8。我想在脚本中检查版本,以便在安装更新版本之前显示错误信息。
<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>
不需要创建目标,你可以在脚本开头使用fail和antversion:
<fail message="Ant 1.8+ required">
<condition>
<not><antversion atleast="1.8" /></not>
</condition>
</fail>
Ant内置属性ant.version
:
<project default="print-version">
<target name="print-version">
<echo>${ant.version}</echo>
</target>
</project>
<!-- 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>
需要Ant版本1.9.8或更高版本(已安装Apache Ant(TM)版本1.9.7,编译日期为2016年4月9日)
在终端中输入,只需执行:
ant -version