Skip to content

Including in Spring Boot project #582

Description

@gboersma

Including the java-sdk as a dependency for a Spring Boot project builds properly, but results in a "NoSuchMethodError: Companion" exception at run-time when initializing an instance of the DaprHttp.

From investigation, it appears that this has to do with the okhttp library and version mismatches:

Without Spring Boot:

[INFO]    \- com.squareup.okhttp3:okhttp:jar:4.9.0:compile
[INFO]       +- com.squareup.okio:okio:jar:2.8.0:compile
[INFO]       |  \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.4.0:compile
[INFO]       \- org.jetbrains.kotlin:kotlin-stdlib:jar:1.4.10:compile
[INFO]          \- org.jetbrains:annotations:jar:13.0:compile

With Spring Boot:

[INFO]    \- com.squareup.okhttp3:okhttp:jar:3.14.9:compile
[INFO]       \- com.squareup.okio:okio:jar:1.17.2:compile

Adding this explicit dependency to the POM fixed the problem:

        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.9.0</version>
        </dependency>

I am scratching my head why this happens since a standalone Spring Boot project does not include the okhttp library, so I am not sure why a Spring Boot + Java SDK project would downgrade this dependency, and I was unable to determine it using the Maven dependency tool.

Referencing the dependency explicitly does fix the problem. Two asks:

  1. Investigate if there is a better way to resolve this issue.
  2. Add a note to the README to help others avoid this issue.

Activity

  1. mthmulders commented on Jul 25, 2021

    @mthmulders
    Contributor

    Duplicate of #515. You can work-around this by changing the Spring Boot version to one that uses a compatible OkHTTP version, or force a compatible OkHttp version in your project by adding the following dependency:

        <dependency>
          <groupId>com.squareup.okhttp3</groupId>
          <artifactId>okhttp</artifactId>
          <version>4.9.0</version>
        </dependency>
  2. artursouza commented on Jul 28, 2021

    @artursouza
    Contributor

    We had a note on this in the README.md file. Please, add it again.

  3. mthmulders commented on Jul 28, 2021

    @mthmulders
    Contributor

    To add a bit more detail regarding your first question: I believe the OkHttp dependency that you see when you do have Spring Boot is "managed" by the Spring Boot "Bill of Materials".

  4. added this to the v1.3 milestone on Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions