Build numbers: major.minor.revision

Dave Jarvis picture Dave Jarvis · Sep 16, 2009 · Viewed 28.8k times · Source

How would you write a build.xml file, using neither custom code nor external dependencies (such as a shell script), that:

  • Generates a build number of the form major.minor.revision (e.g., 01.02.34).
  • Auto-increments the revision on each compile of the source code.
  • Auto-increments the minor version on each execution of a dist(ribution) task.

Additionally:

  • Provides an option to increment the major number.
  • Provides an option to increment the minor number.
  • Whenever the major number is incremented, the minor and revision numbers are set to 0.
  • Whenever the minor number is incremented, the revision number is set to 0.

Bonus:

  • Creates a variable based on the git revision number (like a subversion revision number).

Clarification:

  • Automatic checkout (or commit) is not required.
  • Integration with Subversion is not desired.

Thank you for any examples. Here are some related sites that describe how to perform similar tasks:

Answer

rodrigoap picture rodrigoap · Sep 21, 2009

The build_info.properties file:

build.major.number=00
build.revision.number=00
build.minor.number=00

The build.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project name="project" default="current-number">

<property file="build_info.properties"/>
<property name="build.number" value="${build.major.number}.${build.minor.number}.${build.revision.number}"/>

<target name="current-number">
 <echo>Current build number:${build.number}</echo>
</target>

<target name="compile">
   <antcall target="revision"></antcall>
</target>

<target name="dist">
  <antcall target="minor"></antcall>
</target>

<target name="revision">
    <propertyfile  file="build_info.properties">
            <entry key="build.revision.number" type="int" operation="+" value="1" pattern="00"/>
    </propertyfile>
</target>

<target name="minor">
    <propertyfile  file="build_info.properties">
            <entry key="build.minor.number" type="int" operation="+" value="1" pattern="00"/>
            <entry key="build.revision.number" type="int" value="0" pattern="00"/>
    </propertyfile>
</target>

<target name="major">
    <propertyfile  file="build_info.properties">
            <entry key="build.major.number" type="int" operation="+" value="1" pattern="00"/>
            <entry key="build.minor.number" type="int" value="0" pattern="00"/>
            <entry key="build.revision.number" type="int" value="0" pattern="00"/>
    </propertyfile>
</target>

<target name="all">
    <propertyfile  file="build_info.properties">
            <entry key="build.major.number" type="int" operation="+" value="1" pattern="00"/>
            <entry key="build.minor.number" type="int" operation="+" value="1" pattern="00"/>
            <entry key="build.revision.number" type="int" operation="+" value="1" pattern="00"/>
    </propertyfile>
</target>

</project>