Java 最新版本和旧版本冲突的两个 Maven 依赖项

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

Two Maven Dependency for latest and old version conflicts

javamavenamazon-web-servicesspring-dataspring-data-rest

提问by jAddict

Am using spring-data-dynamoDB project from here, as per its pom.xmlthey have used 1.6.9.1version of aws-java-sdk, but I need to use latest version of aws-java-sdk for my project for using some of its features to implement Amazon s3 too. If I include its dependency,

我从这里使用 spring-data-dynamoDB 项目,根据其pom.xml他们使用了1.6.9.1版本的aws-java-sdk,但我需要为我的项目使用最新版本的 aws-java-sdk 以使用一些它的功能也可以实现 Amazon s3。如果我包括它的依赖,

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk</artifactId>
    <version>1.7.9</version>
</dependency>

am getting an exception as follows,

我收到如下异常,

12:51:25.298 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)': [_relProvider]
12:51:25.307 [main] ERROR o.s.w.c.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.hateoas.config.HypermediaSupportBeanDefinitionRegistrar$Hymanson2ModuleRegisteringBeanPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_halObjectMapper': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.fasterxml.Hymanson.databind.ObjectMapper]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: com.fasterxml.Hymanson.core.JsonFactory.requiresPropertyOrdering()Z
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
.......
.......

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_halObjectMapper': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.fasterxml.Hymanson.databind.ObjectMapper]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: com.fasterxml.Hymanson.core.JsonFactory.requiresPropertyOrdering()Z
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1076) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
.......
.......

I have tried exclusions as follows and also the same result,

我试过如下排除,结果也一样,

<dependency>
   <groupId>org.socialsignin</groupId>
   <artifactId>spring-data-dynamodb</artifactId>
   <version>1.0.0-SNAPSHOT</version>
   <exclusions>
      <exclusion>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
      </exclusion>
   </exclusions>
</dependency>

Is it possible to use latest version of aws-java-sdk in my project now?? or else spring-data-dynamoDB pom.xml have to be updated if so only I am able to use it or what?? Thanks Michaellavelle for that tremendous project. It helps me alot for completing DynamoDB part.

现在可以在我的项目中使用最新版本的 aws-java-sdk 吗?否则 spring-data-dynamoDB pom.xml 必须更新,如果只有我可以使用它或什么?感谢 Michaellavelle 的伟大项目。它对我完成 DynamoDB 部分有很大帮助。

采纳答案by jAddict

Thanks you @user944849. The problem is Hymanson libs used in aws-java-sdk which is lower version as of in spring-data-rest-webmvc and conflicts with it, so by excluding Hymanson libs from aws-java-sdk builds correct. Solution I got is,

谢谢@user944849。问题是 aws-java-sdk 中使用的 Hymanson libs 是 spring-data-rest-webmvc 中的较低版本并与之冲突,因此通过从 aws-java-sdk 中排除 Hymanson libs 构建是正确的。我得到的解决方案是,

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk</artifactId>
    <version>1.7.9</version>
    <exclusions>
        <exclusion>
            <artifactId>Hymanson-core</artifactId>
            <groupId>com.fasterxml.Hymanson.core</groupId>
        </exclusion>
        <exclusion>
            <artifactId>Hymanson-databind</artifactId>
            <groupId>com.fasterxml.Hymanson.core</groupId>
        </exclusion>
        <exclusion>
            <artifactId>Hymanson-annotations</artifactId>
            <groupId>com.fasterxml.Hymanson.core</groupId>
        </exclusion>
    </exclusions>
</dependency>

I am unable to post an answer early because of reputation. This may be useful for others who stuck as like me. Thank you.

由于声誉,我无法尽早发布答案。这可能对像我一样坚持的其他人有用。谢谢你。

回答by user944849

The error is NoClassDefFound for com.fasterxml.Hymanson.core.JsonFactory.requiresPropertyOrdering. I searched for that class in GrepCodeand discovered it is in the com.fasterxml.Hymanson.core:Hymanson-corelibrary. My guess is that the two versions of the aws-java-sdklibrary you tried are specifying different Hymanson-core library versions as transitive dependencies. Your application may be explicitly depending on Hymanson-coreas well - an older version than the one required by the later aws-java-sdk. The project needs to use a version of Hymanson-core that contains the requiresPropertyOrdering method. You should be able to see all of the transitive dependencies by running mvn dependency:tree(or the equivalent in your IDE).

错误是NoClassDefFound for com.fasterxml.Hymanson.core.JsonFactory.requiresPropertyOrdering。我在GrepCode 中搜索了那个类,发现它在com.fasterxml.Hymanson.core:Hymanson-core库中。我的猜测是aws-java-sdk您尝试的两个版本的库将不同的 Hymanson-core 库版本指定为传递依赖项。您的应用程序可能还明确依赖于Hymanson-core比后者所需的版本更旧的版本aws-java-sdk。该项目需要使用包含 requiresPropertyOrdering 方法的 Hymanson-core 版本。您应该能够通过运行mvn dependency:tree(或 IDE 中的等效项)查看所有传递依赖项。

One fix is to add the Hymanson-corelibrary to a <dependencyManagement>block in the project's POM (or the parent POM) to make sure the right version gets used.

一种解决方法是将Hymanson-core库添加到<dependencyManagement>项目 POM(或父 POM)中的块中,以确保使用正确的版本。

回答by Peter Dietz

For some reason excluding Hymanson from aws-java didn't work for me.

出于某种原因,从 aws-java 中排除 Hymanson 对我不起作用。

java.lang.NoSuchMethodError: com.fasterxml.Hymanson.core.JsonFactory.requiresPropertyOrdering()Z

Looking at the issue, it looks like Hymanson is not available, or we have the wrong version floating around in the project. This method appears to have been added in 2.3.0, the latest version of Hymanson. I added a dependency to the latest version of Hymanson, and my code is now happy.

看这个问题,看起来Hymanson不可用,或者我们在项目中浮动了错误的版本。这个方法似乎是在 2.3.0,Hymanson 的最新版本中添加的。我添加了对最新版本 Hymanson 的依赖,现在我的代码很开心。

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-s3</artifactId>
    <version>1.9.6</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.Hymanson.core</groupId>
    <artifactId>Hymanson-core</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.Hymanson.core</groupId>
    <artifactId>Hymanson-databind</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.Hymanson.core</groupId>
    <artifactId>Hymanson-annotations</artifactId>
    <version>2.3.0</version>
</dependency>

I'm not sure if annotation and databind are necessary. Also, I'm working on a huge project, so different forms of Hymanson might be coming in from various other dependencies, jersey, google-http-client-Hymanson2. So, it's also wise to look at the maven dependency graph to see where any Hymanson's are coming from.

我不确定是否需要注释和数据绑定。此外,我正在处理一个巨大的项目,因此不同形式的 Hymanson 可能来自各种其他依赖项,jersey,google-http-client-Hymanson2。因此,查看 maven 依赖关系图以查看任何 Hymanson 的来源也是明智之举。