[英]How to check Ant version inside Ant script
My ant script only works with version >=1.8. 我的ant脚本仅适用于版本> = 1.8。 I want to check the version in the script, so that it displays error if a lesser version installed. 我想检查脚本中的版本,以便在安装较小版本时显示错误。
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>
No need to create a target, you can use fail + antversion at the beginning of your script : 无需创建目标,您可以在脚本开头使用fail + antversion :
<fail message="Ant 1.8+ required">
<condition>
<not><antversion atleast="1.8" /></not>
</condition>
</fail>
Ant has built-in property ant.version
: Ant具有内置属性ant.version
:
<project default="print-version">
<target name="print-version">
<echo>${ant.version}</echo>
</target>
</project>
Version 1.7 of ANT introduced a dedicated antversion task. ANT 1.7版引入了专门的antversion任务。
This functionality is part of several conditions that can be checked by ANT. 此功能是ANT可以检查的几个条件的一部分。
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版本低于要求,则会产生如下错误:
Ant version 1.9.8 or newer is required (Apache Ant(TM) version 1.9.7 compiled on April 9 2016 is installed) 需要Ant版本1.9.8或更高版本(已安装2016年4月9日编译的Apache Ant(TM)版本1.9.7)
在终端类型中,只需执行:
ant -version
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.