如何使用ANT将版本号添加到WAR文件中



我有一个ANT构建文件,我正在其中创建一个WAR文件。在这个ANT文件中,我在WAR文件名中添加了版本信息。但现在的情况是,版本号的主要和次要版本正在同时更新。我的意思是,大和小的增量应该发生为 1.1.0 1.2.0 : : 1.9.0 2.0.0

但现在发生的是

1.1.0 2.2.0 : : 9.9.0 10.10.0

我的Ant代码是

    <target name="war" depends="compile, sethostname, setcurrenttime, setdistdir_withversion">
    <echo>Load properties file</echo>
    <loadproperties srcFile="build_info.properties" prefix="current"/>
    <echo>Dist conf path : ${main.dist.dir}</echo>
    <copy todir="${main.dist.dir}/prop/conf" preservelastmodified="true">
        <fileset dir="${conf.dir}">
            <!-- <include name="**/*_server.xml"/> -->
            <include name="*_catalina_logging.properties"/>
        </fileset>
    <condition property="warfilename" value="${name}">
        <not>
            <isset property="warfilename"/>
        </not>
    </condition>
    <echo>Main Dist directory:${main.dist.dir}</echo>
    <echo>Dist directory:${dist.dir}</echo>
    <echo>WAR filename:${warfilename}</echo>
    <war destfile="${main.dist.dir}/${warfilename}.war"
          webxml="WebContent/WEB-INF/web.xml">
        <fileset dir="conf"/>
        <fileset dir="WebContent"/>
        <classes dir="${build.dir}"/>
    </war>
    <copy todir="${war.archive.dir}" preservelastmodified="true">
        <fileset dir="${main.dist.dir}">
            <include name="*.war"/>
        </fileset>
    </copy>
</target>
<target name="setwarfilename_withversion" depends="revision-deploywar">
    <loadproperties srcFile="build_info.properties" prefix="current"/>
    <echo>Current build number:${current.build.major.number}.${current.build.minor.number}.${current.build.revision.number}</echo>
    <property name="warfilename" value="${name}-${hostname}-${current.build.major.number}.${current.build.minor.number}.${current.build.revision.number}" />
    <echo>WAR filename set : ${warfilename}</echo>
</target>
<target name="sethostname" >
  <property environment="env"/>
  <condition property="hostname" value="${env.HOSTNAME}">
    <os family="unix"/>
  </condition>
  <condition property="hostname" value="${env.COMPUTERNAME}">
    <os family="windows"/>
  </condition>   
  <echo message="host = ${hostname}"/>
</target>
<target name="setcurrenttime" >
    <tstamp>
        <format property="build.time" pattern="MM/dd/yyyy hh:mm:ss aa zzzz" timezone="America/Los_Angeles"/>
    </tstamp>    
  <echo message="host = ${build.time}"/>
</target>
<target name="setbuildinfo">
    <propertyfile  file="build_info.properties">
        <entry key="build.user" value="${user.name}"/>
        <entry key="build.system" value="${hostname}"/>
        <entry key="build.time" value="${build.time}"/>
    </propertyfile>
</target>
<target name="revision">
    <echo>Revision</echo>
    <propertyfile  file="build_info.properties">
        <entry key="build.revision.number" type="int" operation="+" value="1" pattern="00"/>
    </propertyfile>
    <antcall target="setbuildinfo"/>
</target>
<target name="minor" >
    <echo>Minor</echo>
    <propertyfile  file="build_info.properties">
        <entry key="build.minor.number" type="int" operation="+" value="1" pattern="00"/>
    </propertyfile>
   <antcall target="setbuildinfo"/>
</target>
<target name="major" >
    <echo>Major</echo>
    <propertyfile  file="build_info.properties">
        <entry key="build.major.number" type="int" operation="+" value="1" pattern="00"/>
    </propertyfile>
    <antcall target="setbuildinfo"/>
</target>
<target name="revision-deploywar" depends="revision, minor, major" description="Deploy application as a WAR file"/>

问题是以下目标取决于revisionminormajor目标,这将导致所有3个数字都递增。

<target name="revision-deploywar" depends="revision, minor, major" description="Deploy application as a WAR file"/>

通常,主要数字由开发人员手动递增,而次要数字在dist后递增,在编译后进行修订。

查看以下答案以了解更多信息:https://stackoverflow.com/a/1452157/3041189,

相关内容

  • 没有找到相关文章

最新更新