Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

java - Build numbers: major.minor.revision

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:

question from:https://stackoverflow.com/questions/1431315/build-numbers-major-minor-revision

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...