tags:

views:

92

answers:

3

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.

A: 

You can use svn keyword substitution

qrtt1
@qrtt1 In such a case I will pickup the SVN version of this particular file, not of the entire code base.
Vincenzo
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.
Archimedix
+2  A: 

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

Salandur
Really? I can't find any. We are talking about SVN revision, not POM version.
seanizer
i have edited my anwser, had the wrong plugin
Salandur
@Salandur Thanks for the update, but this is exactly what `seanizer` have explained above.
Vincenzo
Salandur
@Vincenzo: when two people give the same answer it can still be correct (+1 for Salandur)
seanizer
@Salandur, I upvoted your answer, thanks!
Vincenzo
+3  A: 

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

seanizer
@seanizer What's wrong with manifest entry? I assume that it is accessible from Java then. Right?
Vincenzo
@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
seanizer
@vincenzo but filtering a jsp or simple text file with maven is a lot easier
seanizer
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 <doUpdate>true</doUpdate> 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