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.

3 Answers 3

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

4
  • What's wrong with manifest entry? I assume that it is accessible from Java then. Right?
    – yegor256
    Oct 12, 2010 at 12:39
  • @vincenzo sure, there was a question about a similar problem yesterday (you can use the answer): stackoverflow.com/questions/3907737/… Oct 12, 2010 at 12:50
  • @vincenzo but filtering a jsp or simple text file with maven is a lot easier Oct 12, 2010 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 <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). Oct 12, 2010 at 13:00
3

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

4
  • Really? I can't find any. We are talking about SVN revision, not POM version. Oct 12, 2010 at 12:24
  • @Salandur Thanks for the update, but this is exactly what seanizer have explained above.
    – yegor256
    Oct 12, 2010 at 12:46
  • that is true, but when i was typing & editing my answer i didn't see his answer :)
    – Salandur
    Oct 12, 2010 at 12:53
  • @Vincenzo: when two people give the same answer it can still be correct (+1 for Salandur) Oct 12, 2010 at 12:55
0

You can use svn keyword substitution

2
  • 1
    In such a case I will pickup the SVN version of this particular file, not of the entire code base.
    – yegor256
    Oct 12, 2010 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, 2010 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.