Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for embedding SVN version number in Java jar manifest?

I see questions like How to get revision number from subversion using maven? but are there any standards (defacto or otherwise) for which actual fields to use in the manifest, for the version # and for the repository URL (i.e., showing that it's on the trunk vs. a branch)? I've seen Implementation-Version used, with and without a leading "r" (for revision), I've seen Implementation-Build: used as well.

edit I removed the maven tag, that shouldn't have been there. My question is about the jar contents, not the tooling per se.

like image 244
Steven R. Loomis Avatar asked Nov 04 '22 07:11

Steven R. Loomis


1 Answers

Unfortunately, jar manifests by itself do not have any standard for version numbering.

But, actually, there is another standard way of getting revision number updated automatically. You could use svn:keywords in order to get current revision number in your files after each commit. There is $Revision$ property for revision substitution and $HeadURL$ for repository URL substitution. You just need to put following string into the file and place this file under version control:

$Revision$ $HeadURL$

If you create manifest on the fly with maven, I would recommend putting following content into version.properties file:

revision=$Revision$
repourl=$HeadURL$

Then include in into pom.xml with the statement (maven should have properties plugin enabled):

<plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-1</version>
    <executions>
      <execution>
        <phase>initialize</phase>
        <goals>
          <goal>read-project-properties</goal>
        </goals>
        <configuration>
          <files>
            <file>version.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>

And then you will be able to put revision number and repo url to the manifest:

<manifest>
  <attribute name="Revision" value="${revision}" />
  <attribute name="Repository URL" value="${repourl}" />
</manifest>

Please also note that you will need to explicitly enable svn:keywords using subversion properties in order to get $Revision$ and $HeadURL$ substituted in your file with actual values. If you will decide to use version.properties, you will need to run following command:

svn propset svn:keywords Revision version.properties
svn propset svn:keywords HeadURL version.properties
like image 145
altern Avatar answered Nov 09 '22 06:11

altern