Warning about using project.parent.version as the module version 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 usually did something like the following in the pom.xml module:

<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 received the following warning for this.

 [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 am curious to know what is the real problem with binding the module version to the parent version, if any? Or is this a case of general warning when any expression is used for a version element, regardless of whether it is project.parent.version.

+75
maven maven-3
Dec 30 '09 at 16:48
source share
1 answer

I am curious to know what is the real problem with binding the module version to the parent version, if any? Or is this a case of general warning when any expression is used for a version element, regardless of whether it is used by project.parent.version.

Well, that would be easy to verify. Since I was curious, I just did it for you using the following pump:

 <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 the mawan really complains

 [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 maven is here, it doesn't make much sense to use the property for the <version> element (at least for project.version), and it's nice that maven complains about it.

And if you want to use the version of the parent pom in the submodules, just remove the <version> from the child poms , they will inherit the version from the parent. What you are doing now is not necessary.

+89
Dec 30 '09 at 19:40
source share



All Articles