Raki Reddy
Raki Reddy

Reputation: 5

versions-maven-plugin:update-property not updating pom.xml

Hi Meier I have used the following goal:

mvn versions:update-property
    -Dproperty="emom.web.dependency.shr.version"
    -Dincludes:org.safeway.com:emom-shr
    -DgenerateBackupPoms=false
    -DallowIncrementalVersios=true
    -DallowSnapshots=true
    clean package

My Job B pom.xml is:

<dependency>
  <groupId>com.safeway.app</groupId>
  <artifactId>emom-shr</artifactId>
  <version>${emom.web.dependency.shr.version}</version>
</dependency>

Under the properties it has the version hard-coded:

<emom.web.dependency.shr.version>19.6.5-SNAPSHOT</emom.web.dependency.shr.version>

My Job A pom.xml:

<groupId>com.safeway.app</groupId>
<artifactId>emom-shr</artifactId>
<version>20.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

When I run the above goal, Maven is picking the latest version (i.e. 20.1.0) from Artifactory but when I check the pom.xml of Job B under properties it still says 19.6.5. I need a way to change the 19.6.5 or current version to latest version available. Am I doing something wrong? I'm not able to figure it out.

Upvotes: 0

Views: 2455

Answers (1)

Ben Cox
Ben Cox

Reputation: 1483

Here's an example of versions-maven-plugin:update-property working in practice. I've used the common Mockito library as an example that works for everyone as it's in Maven Central.

Starting with this POM (noting the mockito-version property):

<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>
    <groupId>abc</groupId>
    <artifactId>def</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <mockito-version>2.22.0</mockito-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito-version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

The simplest way to upgrade it to the latest release version is this:

mvn versions:update-property -Dproperty=mockito-version

Replace mockito-version with emom.web.dependency.shr.version in your case.

You can then start to use more of the goal options to adjust the options. For example, you might:

  • Permit snapshots, not just releases, with -DallowSnapshots=true.

  • Disallow major version updates (i.e. third element from the right) with -DallowMajorUpdates=false. Note that the logic around these version number sections seems a bit flaky in the plugin - or isn't how I expect.

  • Avoid creating backup POMs with -DgenerateBackupPoms=false. This is cleaner, but if you omit this option then you can use mvn versions:revert to get yourself back to where you started.

To apply this to your scenario, I think you need to:

  • Check you've not got typos in your actual command (like you have in the question and comments).

  • Get rid of options that don't appear in the options.

  • Probably, keep things simple by not trying to run this in conjunction with anything else (unless it's in automation), so get rid of the clean package at the end of the command.

Upvotes: 2

Related Questions