I'd like to put revision number on main page of webapp, how can i do that using maven?
P.S. Its two part question, how to get revision number and how to write it into selected file in the project.
I'd like to put revision number on main page of webapp, how can i do that using maven?
P.S. Its two part question, how to get revision number and how to write it into selected file in the project.
The maven build number plugin is the way to go. An example of how to use it is here:
http://www.mojohaus.org/buildnumber-maven-plugin/usage.html
You would use this together with the maven jar plugin to print the SVN commit number to your manifest.
This is a better solution than using a file that contains the SVN commit number, because that adds more moving parts than is really necessary.
If you are using subversion, you can use this plugin to make the SVN revision number available as a maven property
http://code.google.com/p/maven-svn-revision-number-plugin/
I combine this with jar plugin to add the SVN revision to the MANIFEST.MF file for our jar's and war's.
Provided you have the svn command line application, you can use the following code - we use it in our projects (slightly altered)
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<mkdir dir="${project.build.directory}/generated-web-resources/svn"/>
<exec dir="${basedir}" executable="svn"
failifexecutionfails="false"
output="${project.build.directory}/generated-web-resources/svn/svnver.jsp">
<arg line="info"/>
</exec>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated-web-resources/svn</directory>
</resource>
</webResources>
<warSourceExcludes>**/_svn/**</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</build>
You don't say what platform you are using, and you'll pardon me for being unfamiliar with maven. I am supposing it can invoke external programs, and you know how to make it do this.
If on a Unix platform, you should use the program svnversion command, and pipe its output - which is the version number of the working path specified - to a file, which you can then incorporate into your web page as you see fit.
svnversion --help
shows what it can do in detail.
If it is Windows, and you are using TortoiseSVN client, then there is an excellent Windows command line program bundled with it called SubWCRev. This utility will expand macros in a text file you supply with various details of the svn repository you are using - you get to control the format of the output. All very convenient. The help file for this is here: http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html
© 2022 - 2024 — McMap. All rights reserved.