How to inject SVN revision number into JAR?
Asked Answered
M

3

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.

Marble answered 12/10, 2010 at 12:8 Comment(0)
C
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

Cantilever answered 12/10, 2010 at 12:23 Comment(4)
What's wrong with manifest entry? I assume that it is accessible from Java then. Right?Marble
@vincenzo sure, there was a question about a similar problem yesterday (you can use the answer): #3908237Cantilever
@vincenzo but filtering a jsp or simple text file with maven is a lot easierCantilever
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).Zooplasty
G
3

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

Goodkin answered 12/10, 2010 at 12:22 Comment(4)
Really? I can't find any. We are talking about SVN revision, not POM version.Cantilever
@Goodkin Thanks for the update, but this is exactly what seanizer have explained above.Marble
that is true, but when i was typing & editing my answer i didn't see his answer :)Goodkin
@Vincenzo: when two people give the same answer it can still be correct (+1 for Salandur)Cantilever
P
0

You can use svn keyword substitution

Peppy answered 12/10, 2010 at 12:10 Comment(2)
In such a case I will pickup the SVN version of this particular file, not of the entire code base.Marble
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.Paulo

© 2022 - 2024 — McMap. All rights reserved.