0

I want to use svn revision number of pom file as its version.

In pom.xml, if we use buildnumber-maven-plugin, we need to define scm repository url, so that it can check to repository and use buildnumber.

But i want to ask that when we have checkedout code to our system, isn't there any way to get buildnumber without using scm urls. As revision number is stored as subversion in property of each file. we can see it if we right click on file and go to properties.

I want to use buildnumber in version tag of pom and other module's buildnumber in their vaersion tag in dependencies to them.

So if i can store all subversion numbers initially, infact earlier than resolving dependencies, then these subversions can be placed in version of module in dependency and also in version of each pom file.

Problem is that dependencies are resolved before plugin reads version number ( this is what i think), so it cannot resolve expression.

I tried it using properties-maven-plugin to write pom's version number in a file and then read it in other module's pom which is dependent on it. But dependencies are to be resolved before execution of any plugin is started.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
        <execution>
            <id>pre-clean-config</id>
            <phase>validate</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <files>
                    <file>${project.basedir}/../app.properties</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin> 

So, it is not working.

David W.
  • 105,218
  • 39
  • 216
  • 337
HimanshuR
  • 1,390
  • 5
  • 16
  • 35
  • I don't quite understand your question, but you can automatically insert the latest *SVN revision number* into a file using [SVN keyword substitution](http://svnbook.red-bean.com/en/1.7/svn.advanced.props.special.keywords.html). Also see the SO question [Getting the subversion repository number into code](http://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code). That may or may not be what you're looking for. – ThisSuitIsBlackNot Aug 28 '14 at 15:56
  • First what i don't understand is this `As revision number is stored as subversion in property of each file. we can see it if we right click on file and go to properties.` What does this mean? If you checkout your working copy contains your svn revision which can be extracted by `svn info` or `svnversion`. – khmarbaise Aug 29 '14 at 11:22
  • Do you mean you want the version of the project to be the Subversion revision number of your `pom.xml` to be your project's version (`${project.version}`)? If so, this is not a good idea because it means every change in your `pom.xml` becomes a new version of your project. You'd be better off using `SNAPSHOT` versions until you are ready to do an actual release. That's Maven's way of handling constantly changing versions. – David W. Aug 29 '14 at 14:00

1 Answers1

2

Starting with Maven 3.2.1 you can define a property ${revision} which you can use in your versions like this:

 <project...>
   <groupId>..</groupId>
   <artifactId>...</artifactId>
   <version>1.0-${revision}</version>
   ...

The result of this you need to give a property while calling Maven like this:

mvn -Drevision=123456 clean package

This will also work in dependencies etc. Currently one drawback is that you always creating a release from maven's point of view.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235