maven release plugin with parameterized version - maven

is it possible to use the maven release plugin with a multi-module project, where some of the inter-module dependencies are specified using a parameter from the parent pom?
When I try to call release:prepare i get the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.1:prepare (default-cli) on project forest-parent: The version could not be updated: ${some.version} -> [Help 1]
Here is my plugin definition:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
<configuration>
<goals>deploy</goals>
<tagBase>https://svn.domain.com/svn/project/tags</tagBase>
<autoVersionSubmodules>true</autoVersionSubmodules>
<tagNameFormat>#{project.version}</tagNameFormat>
</configuration>
</plugin>
Thanks in advance!

The plugin currently doesn't support parameterized versions from parent (tried v2.2.2 as well). The solution was to use {project.version}.

TL;DR: Accepted answer does not help; Known defect in maven-release-plugin; New CI-Friendly versions in maven 3.5 help somewhat (but don't really solve the OPs issue)
Long version:
The accepted answer doesn't work. I experimented and found the results commented by #Dormouse. Adding this answer for more clarification:
Prefixing the variable name with "project." gets maven release:prepare past the original error, but it will update the version of the custom-versioned module to match all the others
So, as #Dormouse states, the property is useless because after the first maven release call it will no longer refer to the correct version of the module.
For example - some excerpts from a demonstration:
parent pom.xml:
<version>1.0-SNAPSHOT</version>
<properties>
<!-- note the custom property starts with "project" to pass release:prepare -->
<project.version.custom>1.2-SNAPSHOT</project.version.custom>
</properties>
<modules>
<module>custom-versioned-module</module>
<module>dependent-module</module>
</modules
custom-versioned-module/pom.xml:
<parent>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>custom-versioned-module</artifactId>
<!-- this module has 1.2-SNAPSHOT instead of 1.0-SNAPSHOT like the rest -->
<version>1.2-SNAPSHOT</version>
dependent-module/pom.xml
<parent>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>dependent-module</artifactId>
<dependencies>
<dependency>
<artifactId>custom-versioned-module</artifactId>
<!-- experiment with variable version -->
<version>${project.version.custom}</version>
</dependency>
</dependencies>
Now try mvn release:prepare -DdryRun=true and examine the files created. (You can see what the release:perform would do by looking at pom.xml.next - this is used to replace pom.xml if you do not use -DdryRun)
You will see that the version property is left intact, as is the dependency (we wouldn't expect the maven-release-plugin to mess with those), but the actual version of custom-version-module is changed!
custom-versioned-module/pom.xml.next:
<parent>
<version>1.1-SNAPSHOT</version>
</parent>
<artifactId>custom-versioned-module</artifactId>
<version>1.1-SNAPSHOT</version>
The parent version is increased from 1.0 to 1.1, but the module version is decreased from 1.2 to 1.1 (it's simply made the same, not specifically decremented)
Meanwhile the property itself remains at 1.2 so if you actually release, the next build will fail.
Note that this is logged as maven defect here: https://issues.apache.org/jira/browse/MRELEASE-782
And it is somewhat mitigated by the CI-Friendly versioning in 3.5:
https://maven.apache.org/maven-ci-friendly.html

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 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 plugin dependency cannot use parent pom property

I'm hitting a weird edge use case with Maven & curious why it's behaving the way it does.
I'm defining a property in my parent project like so:
<properties>
<some.property.version>1.0.0.0</some.property.version>
</properties>
Now, in a module, I set a version of a dependency for a plugin like so:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>bob</artifactId>
<version>1.0.0.0</version>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>${some.property.version}</artifactId>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
This causes Maven to spit out an error:
[ERROR] 'build.plugins.plugin[org.apache.maven.plugins:bob].dependencies.dependency.version' for org.example:example:jar must be a valid version but is '${some.property.version}'. # line 350, column 16
What's bizarre to me is if I move the property being defined down into the module itself, Maven compiles just fine. Is this a bug? Or are there restrictions of visibility to parent pom properties in a plugin for a module?
An insanely fast response from the Apache Maven's distribution list! The parent pom had been refactored, and the module was pointing to the stale parent's artifactId. Kudos to Robert!
Hi,
This makes me wonder if the "right" parent is used, so please double
check the groupId, artifactId and version. If both parent and module
are part of the same multi-module, be sure that the relativePath is
correct (defaults to ../pom.xml) You could also use "mvn
org.apache.maven.plugins:maven-help-plugin:2.2:effective-pom" to
verify that the property is really there with the expected value. If
this is all as expected, then it seems to be a bug.
thanks, Robert

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

Warning on using project.parent.version as the version of a module in Maven 3

In maven multi-module projects where I want each of the modules to always keep the same version as the parent, I've typically done something like the following in the module's pom.xml:
<parent>
<groupId>com.groupId</groupId>
<artifactId>parentArtifactId</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<groupId>com.groupId</groupId>
<artifactId>artifactId</artifactId>
<packaging>jar</packaging>
<version>${project.parent.version}</version>
<name>name</name>
Since I started using maven 3.0-alpha-5, I get the following warning for doing so.
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.groupid.artifactId:name:jar:1.1-SNAPSHOT
[WARNING] 'version' contains an expression but should be a constant. # com.groupid.artifactId:name::${project.parent.version}, /Users/whaley/path/to/project/child/pom.xml
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
I'm curious to know what the real problem with tying a module's version to the parent version is, if any? Or is this a case of a general warning when any expression, regardless of whether it's project.parent.version, is used for the version element.
I'm curious to know what the real problem with tying a module's version to the parent version is, if any? Or is this a case of a general warning when any expression, regardless of whether it's project.parent.version, is used for the version element.
Well, that would be easy to test. Because I was curious, I just did it for you using the following pom:
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>parent</artifactId>
<groupId>com.mycompany</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.mycompany</groupId>
<artifactId>module</artifactId>
<version>${myversion}</version>
<name>module</name>
<url>http://maven.apache.org</url>
<properties>
<myversion>1.0-SNAPSHOT</myversion>
</properties>
...
</project>
And maven is indeed complaining:
[WARNING] 'version' contains an expression but should be a constant. # com.mycompany:module:${myversion}, /home/pascal/Projects/maven-maven3-testcase/module/pom.xml
To be honest, I think that maven is right here, it doesn't make much sense to use a property for the <version> element (at least not for project.version) and it's nice to have maven complaining about it.
And if you want to use the parent pom version in sub-modules, just remove the <version> tag from the child poms, they will inherit the version from the parent. What you are currently doing is unnecessary.
I might be late here to discuss on this. I got a simple solution for this WARNING.
First of all, if you want that all child modules will take same version as parent, then you just remove <version> tag from child POM and as you include <parent> in child POM, that should be there.
In absence of <version> in child POM, it will automatically take Parent POM version.
Now if you want to use property in parent POM version and want to get the same in all child-modules, you can go through as follow.
There is no limitation on using property in <version> part of parent or child POM. But if you use your own xml tag for specifying that or you use your own property, then WARNING comes, (although this is just warning, everything works as expected).
But if you want to get rid of this WARNING, you can follow these steps:
Create <properties> inside POM.xml as below
<properties>
<revision>1.0.0</revision> <!-- Put your version -->
</properties>
In <version> of the POM.xml, put as follow
<version>${revision}</version>
Sample code snippet (for multi-module project):
<groupId>abc.xyz</groupId>
<artifactId>pqr</artifactId>
<!-- <version>1.0.0</version> -->
<version>${revision}</version>
<packaging>pom</packaging>
<description>Parent POM</description>
<properties>
<revision>1.0.0</revision>
</properties>
Note: Instead of <revision>, if you use any other name (for example, <my.version>), you will face that WARNING
Now if you want to pass version during mvn deploy, you can use mvn deploy "-Drevision=1.0.0-SNAPSHOT" and similarly for mvn install also.
Now if above configuration, you want to use as Parent POM, and you want to use same version in all child module, that can also be done. In each child module POM, use below
<parent>
<groupId>abc.xyz</groupId>
<artifactId>Parent</artifactId>
<!-- <version>1.0.0</version> -->
<version>${revision}</version>
</parent>
<groupId>abc.xyz</groupId>
<artifactId>Child</artifactId>
<!-- <version>1.0.0</version> --> <!-- Automatically inherit parent POM version -->
<name>Demo</name>
For reference, you can go through maven multi module setup
It seems that the warning is correct. See MNG-4717: "the pom that gets deployed will not have the property value resolved, so
anyone depending on that pom will pick up the dependency as being the
string uninterpolated with the ${ } and much hilarity will ensue in your
build process." "However, if one uses flatten-maven-plugin the deployed pom gets a resolved value."

Resources