Maven - 在 Eclipse 中禁止覆盖托管版本警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30782453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:33:06  来源:igfitidea点击:

Maven - Suppress Overriding managed version warning in Eclipse

eclipsemavenspring-bootm2eclipse

提问by The Gilbert Arenas Dagger

I am using spring-boot, and experienced an error similar to the one described here. I added the following to my pom.xml.

我正在使用spring-boot,并遇到了类似于此处描述的错误。我在 pom.xml 中添加了以下内容。

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId><!--$NO-MVN-MAN-VER$-->
        <version>1.1.0.Final</version>
    </dependency>

I am overriding the validation-api 1.0.0 dependency defined in my parent pom.xml, by way of Spring boot, and this gives the pesky warning message:

我通过 Spring boot 覆盖了在我的父 pom.xml 中定义的验证 API 1.0.0 依赖项,这给出了讨厌的警告消息:

Overriding managed version 1.0.0.GA for validation-api

为验证 API 覆盖托管版本 1.0.0.GA

How can I permanently suppress this warning message in Eclipse? It shows up both in my pom.xml and my problems view.

如何在 Eclipse 中永久抑制此警告消息?它显示在我的 pom.xml 和我的问题视图中。

回答by Fred Bricon

When that warning shows up, you can open the Quick-Fix menu on the warning (Ctrl+1) and select

当该警告出现时,您可以打开警告上的“快速修复”菜单 (Ctrl+1) 并选择

Ignore this warning

忽略此警告

This will add the comment on the version line, like :

这将在版本行上添加注释,例如:

<dependency>
   <groupId>javax.validation</groupId>
   <artifactId>validation-api</artifactId>
   <version>1.1.0.Final</version><!--$NO-MVN-MAN-VER$-->
</dependency>

Your problem is you manually added that comment on the wrong line.

您的问题是您在错误的行上手动添加了该评论。

回答by Eric Wang

Since the project is using spring-boot, a more proper answer could be found here: https://stackoverflow.com/a/35385268/1568658

由于该项目正在使用spring-boot,可以在此处找到更正确的答案:https: //stackoverflow.com/a/35385268/1568658

(And since I got the same issue, and the above answer also is not very complete. I would add an answer here.)

(因为我遇到了同样的问题,而且上面的答案也不是很完整。我会在这里添加一个答案。)

Reason of issue:

问题原因:

spring-boothas defined many dependencies & their versions, when you use spring-bootas parent, these dependencies got inherited, and overriding one of the dependency with a different version would get the warning, because it might break other libraries' dependencies.

spring-boot已经定义了许多依赖项及其版本,当您spring-boot用作父项时,这些依赖项被继承,并且使用不同版本覆盖其中一个依赖项会收到警告,因为它可能会破坏其他库的依赖项。

Solution:

解决方案:

Define a property for that dependency between <properties></properties>, to specify the version.

<properties></properties>,之间为该依赖项定义一个属性以指定版本。

e.g

例如

        <properties>
            <reactor.version>2.5.0.BUILD-SNAPSHOT</reactor.version>
        </properties>

How to find the property name:

如何查找属性名称:

  • Open your pom.xmlin IDEA or Eclipse.
  • Ctrl+ Clickon the <parent>tag to open pom of parent, and need to click twice recursively to finally get to the pom file with artifactId as spring-boot-dependencies.
  • Once you have opened that pom, search for your dependency, e.g servlet-api, and you can see the default version.
  • pom.xml在 IDEA 或 Eclipse 中打开。
  • Ctrl+Click<parent>标签上打开父级的 pom,需要递归点击两次才能最终到达 artifactId 为 的 pom 文件spring-boot-dependencies
  • 打开该 pom 后,搜索您的依赖项,例如servlet-api,您可以看到默认版本。

There is a document from spring explains it better: https://spring.io/blog/2016/04/13/overriding-dependency-versions-with-spring-boot

spring 有一个文档解释得更好:https: //spring.io/blog/2016/04/13/overriding-dependency-versions-with-spring-boot

回答by Dmitriy Bereza

Enter version that you need in main pom.

在主 pom.xml 中输入您需要的版本。

This warning means that you are trying to override artifact version that is defined in your main (top level) pom. Just enter version that you need in main pom and you don't even need to use <version />in other poms for this dependency.

此警告意味着您正在尝试覆盖主(顶级)pom 中定义的工件版本。只需在主 pom 中输入您需要的版本,您甚至不需要<version />在其他pom 中使用此依赖项。

回答by S.potty

useful ! I resolve the problem. As the module pom file declare 9.2.12.M0 while the spring-boot refer to the V9.3 . I overwrite the V9.2 in the parent pom file. follow by "Eric Wang"

有用!我解决了这个问题。由于模块 pom 文件声明 9.2.12.M0 而 spring-boot 指的是 V9.3 。我覆盖了父 pom 文件中的 V9.2。跟随“王志强”