How to switch to the latest release version? - maven

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?

Related

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 ?

maven - remove -SNAPSHOT from properties tag in pom.xml

The parent pom.xml of my application contains the following snippet:
...
<version>2.0-SNAPSHOT</version>
...
<properties>
<property.version>1.0-SNAPSHOT</property.version>
</properties>
Essentially, I would like to update both the -SNAPSHOT versions to release versions. i.e., I want my resultant pom.xml to be like:
...
<version>2.0</version>
...
<properties>
<property.version>1.0</property.version>
</properties>
[Note: v1.0 of <property.version> is not yet deployed to the artifactory and also might not be the latest version available
There might exist more properties with SNAPSHOT versions that I do not want to update to release versions]
I figured out a way to update the <version> using maven versions:set plugin. However, I could not find any solution for updating the version (by removing -SNAPSHOT) inside the <properties> tag.
I've looked at documentations for versions:update-properties, versions:update-property.
I am trying to achieve this by using the mvn versions plugin, otherwise I would have to write a script (eg. shell) which would parse and do the needful.

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?

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.

Maven release plugin: Specifying new development version do not affects on pom's custom property

I have following not pretty structured pom:
...
<groupId>xxx</groupId>
<artifactId>yyy</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>
...
<properties>
<xxx.yyy.version>0.1-SNAPSHOT</xxx.yyy.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>xxx</groupId>
<artifactId>aaa</artifactId>
<version>${xxx.yyy.version}</version>
</dependency>
...
</dependencies>
</dependencyManagement>
mvn release:prepare successfully changes version of pom and value of xxx.yyy.version property to specified in cmd release version(e.g. 0.1) - it is good, ok. After, pugin set-up new development version of project (e.g. 0.2-SNAPSHOT) - thats where I got problem: Value of xxx.yyy.version property remains 0.1. Why xxx.yyy.version property not changes to specified new development version 0.2-SNAPSHOT? How to fix it? Thnx in advance
Serious answer: consider using Maven Version Numbers Plugin instead. I've never heard anything good about Release Plugin (at least, I've heard lots of stories like yours).
make sure updateWorkingCopyVersions parameter isn't sets to be false (default true) in maven-release-plugin configuration.
when this param sets to be false versions wont be incremented

Resources