如何在Ant脚本中检查Ant版本

Sum*_*dal 17 java ant

我的ant脚本仅适用于版本> = 1.8.我想检查脚本中的版本,以便在安装较小版本时显示错误.

小智 10

这是一个可能有用的代码片段:

<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>
Run Code Online (Sandbox Code Playgroud)


use*_*613 9

无需创建目标,您可以在脚本开头使用fail + antversion:

<fail message="Ant 1.8+ required">
     <condition>
         <not><antversion atleast="1.8" /></not>
     </condition>
</fail>
Run Code Online (Sandbox Code Playgroud)


Vic*_*kin 8

Ant有内置属性ant.version:

<project default="print-version">
    <target name="print-version">
        <echo>${ant.version}</echo>
    </target>
</project>
Run Code Online (Sandbox Code Playgroud)


Mar*_*nor 5

ANT 1.7版引入了专门的antversion任务.

此功能是ANT可以检查的几个条件的一部分.