Search code examples
javamavenamazon-web-servicesamazon-dynamodbgoogle-vision

Maven - Unable to resolve dependency conflict b/w google-vision beta & aws-sdk sub-components


I'm trying to use google-vision to fetch text from an image (uploaded to AWS S3) and store it in AWS Dynamo DB. I'm encountering dependency conflicts on jackson-core as both google-api and aws-java-sdk are using two different versions.


Dependency Hierarchy

google-api-client: 1.22.0 uses jackson-core: 2.1.3

google-cloud-vision: 0.22.0-beta uses jackson-core: 2.1.3

aws-java-sdk: 1.11.106 uses jackson-core: 2.6.6

I tried "exclusions" and added explicit dependency in pom.xml to use jackson-core: 2.6.6. Google-vision api works fine with that change. However, AmazonDynamoDBClientBuilder fails with below error:


Exception in thread "main" java.lang.IllegalAccessError: tried to access method com.amazonaws.AmazonWebServiceClient.<init>(Lcom/amazonaws/client/AwsSyncClientParams;)V from class com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder.build(AmazonDynamoDBClientBuilder.java:60)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder.build(AmazonDynamoDBClientBuilder.java:26)
    at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
    at com.oneglint.ImageProcessing.AddItem.main(AddItem.java:133)

Following error is displayed when there was version conflict

Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
    at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:537)
    at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:448)
    at com.amazonaws.partitions.PartitionsLoader.<clinit>(PartitionsLoader.java:51)
    at com.amazonaws.regions.RegionMetadataFactory.create(RegionMetadataFactory.java:30)
    at com.amazonaws.regions.RegionUtils.initialize(RegionUtils.java:64)
    at com.amazonaws.regions.RegionUtils.getRegionMetadata(RegionUtils.java:52)
    at com.amazonaws.regions.RegionUtils.getRegion(RegionUtils.java:105)
    at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:239)
    at com.oneglint.ImageProcessing.AddItem.main(AddItem.java:132)

What am I missing here? Thanks for the help..

BTW, I'm using example code from github to achieve this. Here are the links:

DynamoDB example: https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/java/example_code/dynamodb

Google Vision DetectText example: https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/vision/cloud-client/src/main/java/com/example/vision/Detect.java


Additional Details

Both the examples are working fine if executed as independent projects. The problem occurs ONLY when both PutItem (AWS) & Detect (google-vision) classes are brought together in a single project, with appropriate code changes.


Solution

  • After a lot of trial and error approach, the issue is finally solved.

    It appears that I added multiple versions of aws-java-sdk jars during the process and an opennlp jar was associated with the project for some other module.

    I had removed conflicting versions of aws-java-sdk and unnecessary libraries. Also, removed the exclusions and retained only the dependency addition in <dependencymanagement> for jackson-core.

    Dependencies in my final pom listed below:

      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-bom</artifactId>
            <version>1.11.106</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
          <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.6.6</version>
          </dependency>
        </dependencies>
      </dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>com.google.apis</groupId>
          <artifactId>google-api-services-vision</artifactId>
          <version>v1-rev358-1.22.0</version>
        </dependency>
        <dependency>
          <groupId>com.google.api-client</groupId>
          <artifactId>google-api-client</artifactId>
          <version>1.22.0</version>
          <exclusions>
            <exclusion> <!-- exclude an old version of Guava -->
              <groupId>com.google.guava</groupId>
              <artifactId>guava-jdk5</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
          <version>20.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-vision</artifactId>
            <version>0.22.0-beta</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-dynamodb</artifactId>
        </dependency>
      </dependencies>
    

    Hope this helps others..