1

I have a ANT build file in which I am creating a WAR file. In this ANT file I have added version information to the WAR file name. But what is happening is, versions number's major and minor are getting update same time. What I mean to say is the increment of major and minor should happen as 1.1.0 1.2.0 : : 1.9.0 2.0.0

But what is happening is

1.1.0 2.2.0 : : 9.9.0 10.10.0

My Ant code is

    <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"/>
Natraj
  • 397
  • 4
  • 9
  • 35
  • http://stackoverflow.com/questions/14759755/ant-what-is-the-simplest-way-to-add-version-number-to-built-jar might help you – Santhosh Nov 04 '14 at 07:08

1 Answers1

0

The problem is that the following target depends on the revision, minor and major targets which will result in all 3 numbers being incremented.

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

Usually the major number is manually incremented by the developer, while the minor number is incremented after a dist and the revision after a compile.

Have a look at the following answer for more information: https://stackoverflow.com/a/1452157/3041189,

Community
  • 1
  • 1
jmn
  • 564
  • 5
  • 8