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

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.

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:*:*:*:*

Update Maven dependency version in multiple ServiceMix POMs

I am trying to automate process of changing version of a product that has ServiceMix (FuseESB) as an integration module.
Changing the version in each POM is quite easy with the Maven versions plugin:
mvn versions:set -DnewVersion=NEW_VERSION -DgenerateBackupPoms=false
However, I am now struggling with updating version in dependencies that are other modules of this product. Particularly, in many Service Units' POM files there are dependencies like these (where OLD_VERSION is the same, older version number):
<dependencies>
<dependency>
<groupId>com.company.department.product.module1</groupId>
<artifactId>artifact1</artifactId>
<version>OLD_VERSION</version>
</dependency>
<dependency>
<groupId>com.company.department.product.module1</groupId>
<artifactId>artifact2</artifactId>
<version>OLD_VERSION</version>
</dependency>
<dependency>
<groupId>com.company.department.product.module2</groupId>
<artifactId>artifact3</artifactId>
<version>OLD_VERSION</version>
</dependency>
</dependencies>
And I would like to set the version number in those dependencies to "NEW_VERSION".
Do you guys have any ideas?
Just found very simple solution for this - replace dependencies' version with ${project.version} - works for me because in my project the dependencies have the same version as the project itself (they are all artifacts of the same product).

Update minor versions of dependencies stored in properties

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?

Maven. Find versions of included dependencies by dependency

Is it possible, given a dependency such as shown below to determine the versions of included dependencies:
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.5.6</version>
</dependency>
For example, can we determine which version of javax.servlet-api tomcat-embed-core uses as dependency?
I would like to use the same version of javax.servlet-api in a sub-module. But I don't want to include the whole tomcat-embed-core dependency just to get the right version of javax.servlet.api.
(Optional question: Is there an easy way to do this in IntelliJ?)
In Intelij you can right click on the pom -> maven -> show effective pom.
Or I would say best is from the command line:
mvn dependency:list | grep tomcat

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