M2E:版本与父版本重复 - 为什么这是警告?

时间:2021-12-04 23:15:06

I have several Maven projects that each have some common functionality or at least common configuration/dependencies. I extracted this in to a common pom.xml, and then modularlized several facets, for example persistence, Spring related dependencies, and so on - all in their own modules which inherit from this parent POM.

我有几个Maven项目,每个项目都有一些共同的功能或至少是常见的配置/依赖项。我将其解压缩到一个常见的pom.xml,然后模块化了几个方面,例如持久性,Spring相关的依赖关系等等 - 所有这些都在他们自己的模块中继承自这个父POM。

Right now, "Common" is version 1.0.0 and I have "ProjectA" that I wish to inherit from it. I receive the warning:

现在,“Common”是版本1.0.0,我有“ProjectA”,我希望继承它。我收到警告:

Version is duplicate of parent version

版本与父版本重复

I don't fully understand why this is a warning. I thought I had the option of omitting the version from my project POM in order to inherit the version. (I do this for common modules - for example, common-spring adds additional common dependencies for Spring apps, and in fact, ProjectA actually inherits from common-spring.)

我不完全理解为什么这是一个警告。我以为我可以选择省略我的项目POM中的版本以继承该版本。 (我为常见模块执行此操作 - 例如,common-spring为Spring应用程序添加了额外的常见依赖项,事实上,ProjectA实际上继承自common-spring。)

Isn't it just that - an option? If I change my ProjectA version to 1.0.1 or 2.0.0 all is well.

这不是一个选择吗?如果我将ProjectA版本更改为1.0.1或2.0.0一切都很好。

3 个解决方案

#1


51  

It´s just m2e trying to be clever because the version element (like group id) sometimes can be redundant and be can be inherited from the parent POM, so it would be safe to remove this element from your child POM.

它只是m2e试图变得聪明,因为版本元素(如组ID)有时可能是多余的并且可以从父POM继承,因此从您的子POM中删除此元素是安全的。

But sometimes this is not a redundant information, like when the parent and the child project have different life cycles, and m2e should allow this warning to be disabled. Unfortunately there is no way to do this yet: http://dev.eclipse.org/mhonarc/lists/m2e-users/msg01961.html

但有时这不是冗余信息,例如父项和子项目具有不同的生命周期,m2e应允许禁用此警告。不幸的是,还没有办法做到这一点:http://dev.eclipse.org/mhonarc/lists/m2e-users/msg01961.html

UPDATE: As Duncan says bellow, in newer versions you can disable this warning.

更新:正如Duncan所说,在较新版本中,您可以禁用此警告。

#2


52  

Newer versions of m2e (since 1.1) now allow you to disable this warning.

较新版本的m2e(自1.1起)现在允许您禁用此警告。

Preferences > Maven > Warnings > Disable "Version is duplicate of parent version" warning

首选项> Maven>警告>禁用“版本与父版本重复”警告

Original bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=356796

原始错误报告:https://bugs.eclipse.org/bugs/show_bug.cgi?id = 356796

#3


2  

If it really annoys you, use a property to supress the warning with some cunning sleight of hand:

如果它真的让你烦恼,可以用一些狡猾的手法用一个属性来压制警告:

<version>${api.version}</version>
<properties>
    <api.version>0.0.1-SNAPSHOT</api.version>
</properties>

but all you'll really be doing is moving the warning to the console output:

但你真正要做的就是将警告移到控制台输出:

[WARNING] Some problems were encountered while building the effective model for [project]
[WARNING] 'version' contains an expression but should be a constant.

#1


51  

It´s just m2e trying to be clever because the version element (like group id) sometimes can be redundant and be can be inherited from the parent POM, so it would be safe to remove this element from your child POM.

它只是m2e试图变得聪明,因为版本元素(如组ID)有时可能是多余的并且可以从父POM继承,因此从您的子POM中删除此元素是安全的。

But sometimes this is not a redundant information, like when the parent and the child project have different life cycles, and m2e should allow this warning to be disabled. Unfortunately there is no way to do this yet: http://dev.eclipse.org/mhonarc/lists/m2e-users/msg01961.html

但有时这不是冗余信息,例如父项和子项目具有不同的生命周期,m2e应允许禁用此警告。不幸的是,还没有办法做到这一点:http://dev.eclipse.org/mhonarc/lists/m2e-users/msg01961.html

UPDATE: As Duncan says bellow, in newer versions you can disable this warning.

更新:正如Duncan所说,在较新版本中,您可以禁用此警告。

#2


52  

Newer versions of m2e (since 1.1) now allow you to disable this warning.

较新版本的m2e(自1.1起)现在允许您禁用此警告。

Preferences > Maven > Warnings > Disable "Version is duplicate of parent version" warning

首选项> Maven>警告>禁用“版本与父版本重复”警告

Original bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=356796

原始错误报告:https://bugs.eclipse.org/bugs/show_bug.cgi?id = 356796

#3


2  

If it really annoys you, use a property to supress the warning with some cunning sleight of hand:

如果它真的让你烦恼,可以用一些狡猾的手法用一个属性来压制警告:

<version>${api.version}</version>
<properties>
    <api.version>0.0.1-SNAPSHOT</api.version>
</properties>

but all you'll really be doing is moving the warning to the console output:

但你真正要做的就是将警告移到控制台输出:

[WARNING] Some problems were encountered while building the effective model for [project]
[WARNING] 'version' contains an expression but should be a constant.