0

I use the versions-maven-plugin to update the projects version. I want to install the artifact with this updated version but the maven-install plugin uses the old version. How do I have to configure the project to achieve the described behaviour?

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>parse-version</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <propertyPrefix>parsedVersion</propertyPrefix>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>update-version</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>set</goal>
                        <goal>commit</goal>
                    </goals>
                    <configuration>
                        <newVersion>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}-${SVN_REVISION}</newVersion>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Normally I would expect that concerning the maven lifecycle the install plugin should take the new version because the version plugin is executed in the phase validate.

desert
  • 11
  • 4
  • versions-maven-plugin:set goal is only intended for running from command line and NOT within the lifecycle...which will never work, cause the versions-maven-plugin:set goal will change the pom.xml file but during the run the pom.xml has already been loaded into memory and so in result you will always install the old versions. Which Maven Version do you use? – khmarbaise Aug 01 '16 at 18:03
  • Hi, thank for you answer, I use Maven 3.3.x. After using versions plugin from the command line it worked! Maybe someone has the same use case: build-helper:parse-version versions:set -DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}-${SVN_REVISION} – desert Aug 02 '16 at 05:50

1 Answers1

0

Starting with Maven 3.2.1 there is a possibility to use properties as versions which means you can give things like this in your pom file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.soebes.smpp</groupId>
    <artifactId>smpp</artifactId>
    <version>2.2.1</version>
  </parent>

  <groupId>com.soebes.examples.j2ee</groupId>
  <artifactId>parent</artifactId>
  <version>${revision}</version>
  <packaging>pom</packaging>

Furthermore you can of course us this also in parent element of a multi module build like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.soebes.examples.j2ee</groupId>
    <artifactId>parent</artifactId>
    <version>${revision}</version>
  </parent>

  <artifactId>service</artifactId>
  <packaging>ejb</packaging>

This means in consequence you can run Maven via this:

mvn -Drevision=1.2.3-SNAPSHOT install

Or to do a release simply:

mvn -Drevision=1.2.3 install

The drawback here is that you need to give the revision always on command line or in your CI jobs. Apart from that it is possible to use furthermore other things like ${changelist} or ${sha1} which you can of course use in combination. So you can adopt the suggestions like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.soebes.smpp</groupId>
    <artifactId>smpp</artifactId>
    <version>2.2.1</version>
  </parent>

  <groupId>com.soebes.examples.j2ee</groupId>
  <artifactId>parent</artifactId>
  <version>${revision}-${sha1}</version>
  <packaging>pom</packaging>

So you can call maven via this:

mvn -Drevision=1.2.3 -Dsha1=SVNRevision-SNAPSHOT clean package
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Thank you but for my use case the build helper plugin is sufficient, it reads the current version and appends the svn revision number, I don't want to give the version on command line. – desert Aug 02 '16 at 12:49