Update minor versions of dependencies stored in properties - maven

I'm trying to use maven to update to latest minor versions using maven-versions-plugin. The goal use-latest-versions has a flag allowMajorUpdates. But this will set the versions directly in the dependency.
mvn versions:use-latest-versions -DallowMajorUpdates=false
Where I'm located they store version numbers in the properties section of the pom.xml. And they want to keep it that way.
<properties>
<!-- This should be updated to 1.3, even if 2.0 exists -->
<an-app-version>1.2</an-app-version>
</properties>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>an-app</artifactId>
<version>${an-app-version}</version>
</dependency>
</dependencies>
The update-properties goal updates the properties like I want, but I don't want to allow major updates.
mvn versions:update-properties
I'm using maven 3.3.9. Any suggestions?

Related

Maven: automatically update only some libraries to their latest version

I have created a parent pom project and some libraries that I manage.
So, for example:
<parent>
<groupId>my.group</groupId>
<artifactId>parent</artifactId>
<version>1.2.3-SNAPSHOT</version>
</parent>
<dependencies>
...a loooot of them
<dependency>
<groupId>my.group</groupId>
<artifactId>lib</artifactId>
<version>1.2.3-SNAPSHOT</version>
</dependency>
..otheeeeers
</dependencies>
Now, I'd like to always use the latest release or snapshot depending I'm on the develop or release branch.
Problem is that the "new" maven 3 approach only has:
mvn versions:use-latest-releases //release
mvn versions:use-latest-versions //snapshot
But this would update every other dependency and I don't want this! I just want to update the ones having groupId my.group.
Is this possible?
edit:
Following khmarbaise advice I'm using:
mvn versions:use-latest-versions "-Dincludes=com.project.my::::"
But it seems that it only works for non-snapshot versions.
ie. If I define 0.0.2 version of my lib it works, while 0.0.2-SNAPSHOT is not seen..is this normal?
Another thing I noticed is that it only works for inline properties, for example this will not work:
<my-lib.version>0.0.1-SNAPSHOT</my-lib.version>
<groupId>com.project.my</groupId>
<artifactId>mylib</artifactId>
<version>${my-lib.version}</version> <--- undetected, I need to put 0.0.1-SNAPSHOT explicitely
Following the advice of khmarbaise, just call something like
mvn versions:use-latest-releases -Dincludes=mygroup:*:*:*:*

Versions Maven Plugin : do not update to last release available

Let's consider I have a dependency in my pom.xml like this :
<dependency>
<groupId>mygroupid</groupId>
<artifactId>myartifactid</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
For each build, I'd like the version of this dependency to be updated if the release exists.
Thus, I expect the version to be updated from 1.0-SNAPSHOT to 1.0, even if version 2.0 has been released.
It's possible with Versions Maven Plugin, executing mvn versions:use-releases. Fine.
Now, the version is set in a property. The pom.xml looks like this :
<dependency>
<groupId>mygroupid</groupId>
<artifactId>myartifactid</artifactId>
<version>${my.version}</version>
</dependency>
<properties>
<my.version>1.0-SNAPSHOT</my.version>
</properties>
Same as before, I'd like like the version of this dependency to be updated if the release exists.
It looked possible with the same Versions Maven Plugin, executing mvn versions:update-properties. But, with this goal, the version is updated to the last release available (e.g. 2.0 in our case) instead of 1.0.
Any idea of how to get the same behavior as use-release goal with update-properties goal ?

How to skip mvn dependencies set as property using Versions Maven Plugin?

I am using Versions Maven Plugin to update my project versions.
I am using mvn versions:use-latest-versions to update the project dependency. But this disregards the versions set as property.
For instance, I have a pom defined as follows:
<properties>
<vertx.version>3.5.0</vertx.version>
</properties>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-dependencies</artifactId>
- <version>${vertx.version}</version> <!-- This is replaced as below -->
+ <version>3.5.1</version>` <!-- How to ignore this change? -->
<type>pom</type>
<scope>import</scope>
</dependency>
I want to update the version in the property and not in the dependency section.
I can use mvn versions:update-properties to update the properties.
The problem is I want to use a combination of both the goals to update the properties.
Executing the 2 goals one after the other also doesn't help.
The desired behavior can be achieved using mvn versions:update-properties and mvn versions:use-latest-releases in succession instead of mvn versions:use-latest-versions.

How to switch to the latest release version?

I'm using the versions plugin to update the dependencies to my projects, where the versions are defined in properties, e.g:
<properties>
<version.property>1.6-SNAPSHOT</version.property>
</properties>
<dependencies>
<dependency>
<groupId>com.foo.bar</groupId>
<artifactId>myProject</artifactId>
<version>${version.property}</version>
</dependency>
</dependencies>
Now versions:update-properties is doing a good job here, but for one situation. Lets say the version.property is set to the latest snapshot version available in my repo: 1.6-SNAPSHOT.
I would expect from the following command, that the version changes to 1.5
mvn versions:update-properties
But it stays on the latest snapshot.. Now what I'm missing here? The docs claims:
...executing the update-properties goal will update the version.property property to the latest common version available in your local repository and all currently active remote repositories
The parameter allowSnapshots is false by default. So, whats going on?
Why the version isn't updating to the latest release, which is 1.5? How can I do this?

Update pom to use released versions

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.
I see two approaches here:
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
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!
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.

Resources