commercetools / commercetools-sdk-java-v2

The e-commerce SDK from commercetools for Java.
https://commercetools.github.io/commercetools-sdk-java-v2/javadoc/index.html
Apache License 2.0
35 stars 16 forks source link

With a Micronaut the ApiFactory throws exception because no class net/jodah/failsafe/Policy #112

Closed peniakoff closed 3 years ago

peniakoff commented 3 years ago

I'm trying to run Commercetools client based on the Micronaut function (for AWS Lambda purposes). I'm using Micronaut core v2.3.1. It is importatnt because when I try to connect to the Commercetools without Micronaut stuff, everything works fine. But now method constructApiHttpRequest (class io.vrap.rmf.base.client.oauth2.ClientCredentialsTokenSupplier#constructApiHttpRequest) can not build new ApiHttpRequest(ApiHttpMethod.POST, URI.create(tokenEndpoint), headers, body.getBytes(StandardCharsets.UTF_8)) because of exception Method threw 'java.lang.NoClassDefFoundError' exception. Cannot evaluate io.vrap.rmf.base.client.ApiHttpRequest.toString(). But I can not investigate where basically there is any sub-method which uses toString() on the ApiHttpRequest.

In the stack tree we can find also: net/jodah/failsafe/Policy: java.lang.NoClassDefFoundError java.lang.NoClassDefFoundError: net/jodah/failsafe/Policy at io.vrap.rmf.base.client.MiddlewareFactory.createDefault(MiddlewareFactory.java:23) at io.vrap.rmf.base.client.ClientFactory.create(ClientFactory.java:85) at io.vrap.rmf.base.client.ClientFactory.create(ClientFactory.java:76) at com.commercetools.api.defaultconfig.ApiFactory.defaultClient(ApiFactory.java:158) at com.commercetools.api.defaultconfig.ApiFactory.lambda$create$6(ApiFactory.java:57) at com.commercetools.api.defaultconfig.ApiFactory.create(ApiFactory.java:106) at com.commercetools.api.defaultconfig.ApiFactory.create(ApiFactory.java:57)

Package net.jodah.failsafe (in version 2.4.0) is localized ofc in my dependencies tree.

Expected behavior Possibiity to use CT Java SDK with Micronaut framework.

Desktop (please complete the following information):

peniakoff commented 3 years ago

Problem solved. I've added two dependencies below with "compile" scope.

  <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.11</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>net.jodah</groupId>
        <artifactId>failsafe</artifactId>
        <version>2.4.0</version>
        <scope>compile</scope>
    </dependency>

AWS SAM CLI is building application based on local Maven repositories. When package is set with scope "runtime" SAM builder doesn't use it during building process and finally this package is not located in runtime. Maybe could you move these packages to the "compile" scope for the future?

jenschude commented 3 years ago

Today the 3.1.0 has been released and this now declares also all runtime dependencies with api scope in the gradle file. Which will translate to compile scope in the pom file

peniakoff commented 3 years ago

Thanks @jenschude!

peniakoff commented 3 years ago

With SDK v3.1.0 problem was solved! :+1: