How to check Ant version inside Ant script

橙三吉。 提交于 2019-12-09 14:36:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!