7

I want my JAR/WAR application to know what is the SVN revision number of its source code. I want this revision number to be later rendered for web end-users at the bottom of a web page, etc.

Is there any existing Maven plugin to automate the process? I think that the plugin has to collect the information from svn and save to some file, like src/resources/revision.txt.

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
yegor256
  • 102,010
  • 123
  • 446
  • 597

3 Answers3

4

This page provides the answer to an almost identical problem:

Maven CookBook: How To Add SVN Revision To A JAR Manifest?

In your case, instead of building a manifest entry, you need to use the buildNumber variable for resource filtering

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • What's wrong with manifest entry? I assume that it is accessible from Java then. Right? – yegor256 Oct 12 '10 at 12:39
  • @vincenzo sure, there was a question about a similar problem yesterday (you can use the answer): http://stackoverflow.com/questions/3907737/how-to-read-manifest-mf-from-pojo-class-not-a-servlet-instantiated-by-spring – Sean Patrick Floyd Oct 12 '10 at 12:50
  • @vincenzo but filtering a jsp or simple text file with maven is a lot easier – Sean Patrick Floyd Oct 12 '10 at 12:54
  • 1
    beware: this revision number will be only the revision of the topmost project directory. if you have separately ran "svn up" in some subdirectory, this will not be recorded. Not an issue, if you turn on the true option. Safer option would be to list the revisions of all subdirectories and files, but I have not yet come across a publicly available plugin that would be capable of this (we have one developed in-house, it also records the SVN URL so you know which branch the code is from). – Neeme Praks Oct 12 '10 at 13:00
3

use the versions-maven-plugin buildnumber-maven-plugin from the Codehaus Mojo project. Provides lots of options to do this.

Salandur
  • 6,409
  • 2
  • 22
  • 23
0

You can use svn keyword substitution

qrtt1
  • 7,746
  • 8
  • 42
  • 62
  • 1
    In such a case I will pickup the SVN version of this particular file, not of the entire code base. – yegor256 Oct 12 '10 at 12:14
  • Keyword substitution is only performed on changed files, i.e. no change, no new revision number. One has to read the current project's revision from the `.svn` directory. MediaWiki has code that does that, however it is written in PHP. – Arc Oct 12 '10 at 12:16