0

Trying to find a way to update a pom to use latest versions of a RELEASED dependency instead of SNAPSHOT.

We have a assembly project that assembles an image to be deployed that during development uses SNAPSHOT dependencies.

But now I want to update the dependencies to use the latest released dependencies. Tried using versions:use-latest-releases but it only affects already released versions in the pom.

Any ideas?

EDIT (can not for security reasons post the pom but here's an example)

<project>
    ....
    <dependencies>
        <dependency>
            <groupId>a.b.c</groupId>
            <artifactId>c-d-f</artifactId>
            <version>1.0.1-SNAPSHOT</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>a.b.c</groupId>
            <artifactId>g-h-i</artifactId>
            <version>1.1.6-SNAPSHOT</version>
            <type>war</type>
        </dependency>
        ...
    </dependencies>
    ...
</project>

Given that component a-b-c and g-h-i has been released with version 1.0.1 and 1.1.6 I want to replace their versions in this pom with these version numbers. Basically remove any snapshot dependencies in the pom.

EDIT I should add that is to be an automated process with minimal human interaction. For some reason I can only get versions:update-properties to work if versions are already in release state. If I have a snapshot version 0.0.1-SNAPSHOT and want to update it to 0.0.1 it doesn't happen and I have verified the release exists. Same thing with versions:use-latest-relese, and versions:use-releases does nothing at all.

jne
  • 457
  • 2
  • 9
  • 22
  • Can you post your pom.xml? But I do not undertand well what happens? What you want is to change in your pom.xml a dependency for Snapshot to release? If it is that, why can not do it manually? – Iker Aguayo Oct 14 '14 at 07:59
  • Is maybe `versions:use-releases` what you want? Description: Replaces any -SNAPSHOT versions with the corresponding release version (if it has been released). http://mojo.codehaus.org/versions-maven-plugin/use-releases-mojo.html – lexicore Oct 14 '14 at 08:33
  • @jne if you find here a helping answer, you can mark is "accepted"... – OhadR Oct 14 '14 at 20:48

2 Answers2

0

I see two approaches here:

  1. You can create multiple profiles in your maven pom. Best way is to create a profile of "snapshot" and one for "release". Described here: Different dependencies for different build profiles in maven
  2. You can use maven pom properties to define variables for your dependency versions. See here: http://books.sonatype.com/mvnref-book/reference/resource-filtering-sect-properties.html#resource-filtering-sect-user-defined

Hope that helps!

Community
  • 1
  • 1
L.Butz
  • 2,466
  • 25
  • 44
0

You can use maven properties in your pom.xml, such as:

<properties>
    <c-d-f.version>1.0.1-SNAPSHOT</c-d-f.version>
    <g-h-i.version>1.1.6-SNAPSHOT</g-h-i.version>
</properties>


<dependencies>
        <dependency>
            <groupId>a.b.c</groupId>
            <artifactId>c-d-f</artifactId>
            <version>${c-d-f.version}</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>a.b.c</groupId>
            <artifactId>g-h-i</artifactId>
            <version>${g-h-i.version}</version>
            <type>war</type>
        </dependency>
        ...
</dependencies>

and when you want to change the versions, you can use maven-versions-plugin, with the following command, such as:

versions:update-properties -Dproperties=[${release_version}] -DincludeProperties={c-d-f.version}

EDIT:

Note that if you wanna use SNAPSHOTS, you need to add -DallowSnapshots. Read here for more options. And yes, the version needs to exist in the repo, otherwise it will fail. BTW did you use brackets, such as -Dproperties=[0.0.1]? after you read the link I sent you, you will see that this commmand's input is a range, so you must use brackets in order to specify a unique version.

OhadR
  • 8,276
  • 3
  • 47
  • 53
  • This is exactly the thing I am looking for, but for some reason it always takes latest snapshot version. I tried even being explicit with allowSnapshots=false, but there is no way changing snapshot to release. Any ideas why? Is there a bug or something? – Piotr Tempes Aug 02 '16 at 14:30
  • I think that if you wanna change from snapshots to release, the best approach is to use maven-release-plugin. – OhadR Aug 02 '16 at 14:57
  • Does maven-release-plugin work on properties section? – Piotr Tempes Aug 03 '16 at 16:05
  • yes, it knows to update therelevant props. http://maven.apache.org/maven-release/maven-release-plugin/ – OhadR Aug 03 '16 at 16:54