java Maven 依赖冲突

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17335255/
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-11-01 01:42:45  来源:igfitidea点击:

Maven Dependency Conflict

javamavendependenciesproject-managementpom.xml

提问by Amol Sharma

A maven project consisting of some modules. One of my module is using guava dependency of google version 11.0.2. Now i am integrating another module in my project which is also using guava but version 14.

由一些模块组成的 maven 项目。我的模块之一是使用谷歌版本的番石榴依赖11.0.2。现在我正在我的项目中集成另一个模块,该模块也使用番石榴但版本14

So i want that new module uses guava version 14but remaining project use guava version 11.0.2. I have tried adding <exclusion></exclusion>of guava to the new module but it didn't work.

所以我希望新模块使用 guava 版本,14但其余项目使用 guava 版本11.0.2。我曾尝试将<exclusion></exclusion>番石榴添加到新模块中,但没有奏效。

Any tips to solve this.

解决此问题的任何提示。

Update: @Guillaume Darmont's Answer solves the problem for different modules. but now my problem is, the new modules has 2 dependency one of the them is using guava 11.0.2and other is using 14.0. how to manage this. can we specify separately in the pom of the module that which version of the guava it should use.?

更新:@Guillaume Darmont 的回答解决了不同模块的问题。但现在我的问题是,新模块有 2 个依赖项,其中一个使用番石榴11.0.2,另一个使用14.0. 如何管理这个。我们可以在模块的 pom 中单独指定它应该使用哪个版本的番石榴吗?

采纳答案by Guillaume Darmont

As I understand your question, you may add a <dependencyManagement>for guavain your new module pom.xml :

据我了解您的问题,您可以在新模块 pom.xml 中添加一个<dependencyManagement>for guava

<dependencyManagement>
  <dependencies>
      <dependency>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
          <version>14.0.1</version>
      </dependency>
  </dependencies>
</dependencyManagement>

回答by user1573133

mvn dependency:treecommand will help to determine which module is bringing the Guava 14 jar file.

mvn dependency:tree命令将有助于确定哪个模块带来了 Guava 14 jar 文件。

回答by Kalpak Gadre

Firstly try mvn dependency treeand check the output it is possible that 11.0.2has been transitively referenced from more than one of your projects dependencies and you will need to add exclusion to all the dependencies directly / indirectly pulling down the specific guava version you are trying to exclude.

首先尝试mvn dependency tree检查输出,它可能11.0.2已经从多个项目依赖项中传递引用,并且您需要直接/间接地向所有依赖项添加排除项,以降低您尝试排除的特定番石榴版本。

Secondly resolving this conflict may not be straight forward. Looking at version number transition (11 to 14) sounds to me like a major transition, and you may have better chances keeping the 14 version and excluding the 11 something.

其次,解决这一冲突可能并不容易。查看版本号转换(11 到 14)对我来说听起来像是一个主要的转换,并且您可能有更好的机会保留 14 版本并排除 11 某些内容。

If the version change is not compatible with your application, you have pretty much no option but to use something like OSGito ensure you can run different versions of same library in the project.

如果版本更改与您的应用程序不兼容,您几乎别无选择,只能使用类似的方法OSGi来确保您可以在项目中运行同一库的不同版本。