Two Maven Dependency for latest and old version conflicts

11,231

Solution 1

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.

Solution 2

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.

Solution 3

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.

Share:
11,231
jAddict
Author by

jAddict

Trying to create a book of history but unable to start the prefix

Updated on July 28, 2022

Comments

  • jAddict
    jAddict almost 2 years

    Am using spring-data-dynamoDB project from here, as per its pom.xml they have used 1.6.9.1 version 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,

    <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$Jackson2ModuleRegisteringBeanPostProcessor#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.jackson.databind.ObjectMapper]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: com.fasterxml.jackson.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.jackson.databind.ObjectMapper]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: com.fasterxml.jackson.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.

  • Rahul Dabas
    Rahul Dabas over 9 years
    Thanks. Helped me when i bumped my dependency from 1.8.9.1 to 1.8.11.
  • Etienne Dufresne
    Etienne Dufresne almost 9 years
    Thank you. I had a similar issue when I added Google Cloud Storage to my project. In my case excluding jackson-core made it work.
  • dbort
    dbort over 8 years
    I ran into a similar problem with Jackson and Google Dataflow. Exclusions didn't help me, but it worked when I added the versions of Jackson I needed at the very top of my <dependencies> list (thus putting them at the beginning of the classpath).
  • Ziv Gabovitch
    Ziv Gabovitch over 6 years
    @dbort, Thanks! I had the same issue (in an uber-jar creation) - tried everything, this was the only thing that worked.