Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch current subversion revision number and URL with maven

I make a checkout of some branch or tag from subversion repository and then build the project with maven.

Now, I'd like to get store current revision number and URL to some file. How can I do that? That is, I'd like to get revision number and URL of whatever branch/tag I have made checkout of.

I know about buildnumber-maven-plugin but I think it doesn't do this. It fetches revision number of branch that is specified in pom.xml.

like image 685
Juha Syrjälä Avatar asked Dec 23 '22 12:12

Juha Syrjälä


2 Answers

You could use the maven-antrun-plugin to execute svnversion.

<project>
  […]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <configuration>
              <tasks>
                <exec executable="sh">
                  <arg value="-c"/>
                  <arg value="svnversion &gt;version.txt" />
                </exec>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  […]
</project>

NB: I've used sh -c to run svnversion, so I can redirect the output to a file. I don't think that you can get the output into a property for use by the maven build.

You can use the same approach to run svn info --url.

like image 63
Dominic Mitchell Avatar answered Dec 27 '22 10:12

Dominic Mitchell


As said already the Maven Build Number Plugin can be used to find the revision.

As for the URL: Maven Practice is to put it in the POM using the <scm>-tag. If you configure this right once and then use the appriopriate Maven plugins (maven-scm-plugin, maven-release-plugin) for branching, tagging, releasing, etc. you can be sure the <scm>-tag always contains the right url.

like image 42
Thomas Marti Avatar answered Dec 27 '22 09:12

Thomas Marti