Build and Version Numbering for Java Projects (ant, cvs, hudson)

后端 未结 9 983
野的像风
野的像风 2020-11-29 14:38

What are current best-practices for systematic build numbering and version number management in Java projects? Specifically:

  • How to manage build numbers sy

相关标签:
9条回答
  • 2020-11-29 15:15

    Software:

    • SVN
    • Ant
    • Hudson, for continuous integration
    • svntask, an Ant task to find SVN revision: http://code.google.com/p/svntask/

    Hudson has three builds/jobs: Continuous, Nightly and Release.

    For a Continuous/Nightly build: Build number is the SVN revision, found using svntask.

    For a Release build/job: Build number is the Release number, read by Ant, from a Properties file. The properties file can also be distributed with the release for displaying the build number at runtime.

    The Ant build script puts the build number in the manifest file of jar/war files that are created during the build. Applies to all builds.

    Post-build action for Release builds, done easily using a Hudson plug-in: tag SVN with the build number.

    Benefits:

    • For a dev version of a jar/war, the developer can find the SVN revision from the jar/war and look up the corresponding code in SVN
    • For a release, the SVN revision is the one corresponding to the SVN tag that has the release number in it.

    Hope this helps.

    0 讨论(0)
  • 2020-11-29 15:18

    Your build.xml

    ...
    <property name="version" value="1.0"/>
    ...
    <target name="jar" depends="compile">
        <buildnumber file="build.num"/>
        <manifest file="MANIFEST.MF">
            ...
            <attribute name="Main-Class" value="MyClass"/>
            <attribute name="Implementation-Version" value="${version}.${build.number}"/>
            ...
        </manifest>
    </target>
    ...
    

    Your java code

    String ver = MyClass.class.getPackage().getImplementationVersion();
    
    0 讨论(0)
  • 2020-11-29 15:19

    For several of my projects I capture the subversion revision number, time, user who ran the build, and some system information, stuff them into a .properties file that gets included in the application jar, and read that jar at runtime.

    The ant code looks like this:

    <!-- software revision number -->
    <property name="version" value="1.23"/>
    
    <target name="buildinfo">
        <tstamp>
            <format property="builtat" pattern="MM/dd/yyyy hh:mm aa" timezone="America/New_York"/>
        </tstamp>        
        <exec executable="svnversion" outputproperty="svnversion"/>
        <exec executable="whoami" outputproperty="whoami"/>
        <exec executable="uname" outputproperty="buildsystem"><arg value="-a"/></exec>
    
        <propertyfile file="path/to/project.properties"
            comment="This file is automatically generated - DO NOT EDIT">        
            <entry key="buildtime" value="${builtat}"/>
            <entry key="build" value="${svnversion}"/>
            <entry key="builder" value="${whoami}"/>
            <entry key="version" value="${version}"/>
            <entry key="system" value="${buildsystem}"/>
        </propertyfile>
    </target>
    

    It's simple to extend this to include whatever information you might want to add.

    0 讨论(0)
提交回复
热议问题