0

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.

Ben Cox
  • 1,393
  • 10
  • 28
  • Is it a typo that you have 'Dproperty=emom.web.dependency.shr.version' with no leading hyphen '-D'? – Ben Cox Jan 30 '20 at 11:22
  • Hello Ben, My bad it's a typo actually mvn versions:update-property -Dproperty="emom.web.dependency.shr.version" -Dincludes:org.safeway.com:emom-shr -DgenerateBackupPoms=false -DallowIncrementalVersios=true -DallowSnapshots=true clean package' I'm using the goals like this – Raki Reddy Jan 30 '20 at 21:12
  • Ah OK and -DallowIncrementalVersios=true, do you mean -DallowIncrementalUpdates=true? – Ben Cox Jan 30 '20 at 21:19
  • Yes Ben, not sure if I'm not following the correct proccess – Raki Reddy Jan 30 '20 at 21:27

1 Answers1

1

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.

Ben Cox
  • 1,393
  • 10
  • 28
  • Thanks Ben now I can see my pom file is been updated with latest version there was a typo on my goals, I was being stupid should have realized earlier. – Raki Reddy Jan 30 '20 at 22:39
  • Good to hear you got there. If you're happy that my answer fixed your question, please mark it with the check/tick on the left so future users know it works. – Ben Cox Jan 31 '20 at 00:52