How to get revision number from subversion using maven?
Asked Answered
D

4

35

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.

Delilahdelimit answered 17/3, 2009 at 14:51 Comment(0)
F
27

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.

Farman answered 26/3, 2009 at 5:14 Comment(2)
I found useful additional info at apollo.ucalgary.ca/tlcprojectswiki/index.php/Public/… , including code to retrieve the version numbers if stored in the manifest.Metallize
ucalgary link is dead. Wayback machine link here: web.archive.org/web/20101021043408/http://apollo.ucalgary.ca/…Snailpaced
S
7

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.

Simons answered 19/11, 2010 at 23:30 Comment(0)
M
4

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>
Miles answered 25/3, 2009 at 20:31 Comment(0)
S
1

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

Sitin answered 17/3, 2009 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.