Two Maven Dependency for latest and old version conflicts

孤街浪徒 提交于 2019-11-30 19:39:23

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

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk</artifactId>
    <version>1.7.9</version>
    <exclusions>
        <exclusion>
            <artifactId>jackson-core</artifactId>
            <groupId>com.fasterxml.jackson.core</groupId>
        </exclusion>
        <exclusion>
            <artifactId>jackson-databind</artifactId>
            <groupId>com.fasterxml.jackson.core</groupId>
        </exclusion>
        <exclusion>
            <artifactId>jackson-annotations</artifactId>
            <groupId>com.fasterxml.jackson.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.

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

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

Looking at the issue, it looks like jackson 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 jackson. I added a dependency to the latest version of jackson, and my code is now happy.

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-s3</artifactId>
    <version>1.9.6</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-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 jackson might be coming in from various other dependencies, jersey, google-http-client-jackson2. So, it's also wise to look at the maven dependency graph to see where any jackson's are coming from.

user944849

The error is NoClassDefFound for com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering. I searched for that class in GrepCode and discovered it is in the com.fasterxml.jackson.core:jackson-core library. My guess is that the two versions of the aws-java-sdk library you tried are specifying different jackson-core library versions as transitive dependencies. Your application may be explicitly depending on jackson-core as well - an older version than the one required by the later aws-java-sdk. The project needs to use a version of jackson-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).

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!