在Maven 3中使用project.parent.version作为模块版本的警告 [英] Warning on using project.parent.version as the version of a module in Maven 3
问题描述
在Maven多模块项目中,我希望每个模块始终与父模块保持相同的版本,我通常在模块的pom.xml中执行以下操作:
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>
自从我开始使用maven 3.0-alpha-5以来,我收到以下警告.
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]
我很想知道将模块版本与父版本绑定的真正问题是什么(如果有)?还是将任何表达式(无论是否为project.parent.version)用于version元素时,这都是一般警告的情况.
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.
推荐答案
我很想知道将模块版本与父版本绑定的真正问题是什么(如果有)?还是将任何表达式(无论是否为project.parent.version)用于version元素时,这都是一般警告的情况.
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.
嗯,这很容易测试.因为我很好奇,所以我使用以下pom为您做到了:
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>
行家确实在抱怨:
[WARNING] 'version' contains an expression but should be a constant. @ com.mycompany:module:${myversion}, /home/pascal/Projects/maven-maven3-testcase/module/pom.xml
说实话,我认为maven就在这里,对<version>
元素使用属性没有多大意义(至少对于project.version而言不是),让maven抱怨是一件好事.
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.
如果您想在子模块中使用父pom版本,只需从子pom中删除<version>
标签,它们就会从父pom中继承该版本.您当前正在做的事情是不必要的.
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.
这篇关于在Maven 3中使用project.parent.version作为模块版本的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!