在 Maven 3 中使用 project.parent.version 作为模块版本的警告 [英] Warning on using project.parent.version as the version of a module in Maven 3

查看:426
本文介绍了在 Maven 3 中使用 project.parent.version 作为模块版本的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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>

maven 确实在抱怨:

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

老实说,我认为 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 中删除 标签,它们将继承版本从父母.您目前所做的事情是不必要的.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆