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:
在maven多模块项目中,我希望每个模块始终保持与父模块相同的版本,我通常在模块的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.
由于我开始使用maven 3.0-alpha-5,因此我得到了如下警告。
[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.
我很想知道将一个模块的版本与父版本绑定到底有什么问题?或者这是一个一般的警告当任何表达式,不管它是项目。父。版本,用于版本元素。
1 个解决方案
#1
79
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:
这很容易测试。因为我很好奇,我只是用下面的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:
而maven确实在抱怨:
[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.
老实说,我认为maven就在这里,使用 <版本> 元素(至少不是project.version)的属性是没有多大意义的,有maven来抱怨它是件好事。
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 just useless.
如果您想要在子模块中使用父pom版本,只需将
#1
79
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:
这很容易测试。因为我很好奇,我只是用下面的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:
而maven确实在抱怨:
[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.
老实说,我认为maven就在这里,使用 <版本> 元素(至少不是project.version)的属性是没有多大意义的,有maven来抱怨它是件好事。
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 just useless.
如果您想要在子模块中使用父pom版本,只需将