Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“NoSuchMethodErrors” due to multiple versions of com.squareup.okhttp3:okhttp:jar #925

Closed
Bing-ok opened this issue Aug 15, 2020 · 5 comments

Comments

@Bing-ok
Copy link

Bing-ok commented Aug 15, 2020

Hi, there are multiple versions of com.squareup.okhttp3:okhttp in github-api-master. As shown in the following dependency tree, according to Maven's “nearest wins” strategy, only com.squareup.okhttp3:okhttp:4.4.1 can be loaded, and com.squareup.okhttp3:okhttp:3.12.3 will be shadowed.

As com.squareup.okhttp3:okhttp:3.12.3 has not been loaded during the building process, several methods are missing. However, the missing methods:
1. okhttp3.internal.Version: java.lang.String userAgent()

Check for details of invocation
paths------
<org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory$DelegatingHttpsURLConnection: java.io.OutputStream getOutputStream()> github-api-master\target\classes
<okhttp3.internal.huc.OkHttpURLConnection: java.io.OutputStream getOutputStream()> Repositories\com\squareup\okhttp3\okhttp-urlconnection\3.12.3\okhttp-urlconnection-3.12.3.jar
<okhttp3.internal.huc.OkHttpURLConnection: okhttp3.Call buildCall()> Repositories\com\squareup\okhttp3\okhttp-urlconnection\3.12.3\okhttp-urlconnection-3.12.3.jar
<okhttp3.internal.huc.OkHttpURLConnection: java.lang.String defaultUserAgent()> Repositories\com\squareup\okhttp3\okhttp-urlconnection\3.12.3\okhttp-urlconnection-3.12.3.jar
<okhttp3.internal.Version: java.lang.String userAgent()>

2. okhttp3.internal.http.HttpDate: java.lang.String format(java.util.Date)

Check for details of invocation
paths------
<org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory$DelegatingHttpsURLConnection: void setIfModifiedSince(long)> github-api-master\target\classes
<okhttp3.internal.huc.OkHttpURLConnection: void setIfModifiedSince(long)> Repositories\com\squareup\okhttp3\okhttp-urlconnection\3.12.3\okhttp-urlconnection-3.12.3.jar
<okhttp3.internal.http.HttpDate: java.lang.String format(java.util.Date)>

3. okhttp3.internal.platform.Platform: void log(int,java.lang.String,java.lang.Throwable)

Check for details of invocation
paths------
<org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory$DelegatingHttpsURLConnection: void setRequestProperty(java.lang.String,java.lang.String)> github-api-master\target\classes
<okhttp3.internal.huc.OkHttpURLConnection: void setRequestProperty(java.lang.String,java.lang.String)> Repositories\com\squareup\okhttp3\okhttp-urlconnection\3.12.3\okhttp-urlconnection-3.12.3.jar
<okhttp3.internal.platform.Platform: void log(int,java.lang.String,java.lang.Throwable)>

4. okhttp3.internal.http.StatusLine: okhttp3.internal.http.StatusLine get(okhttp3.Response)

Check for details of invocation
paths------
<org.kohsuke.github.extras.okhttp3.ObsoleteUrlFactory$DelegatingHttpsURLConnection: java.lang.String getHeaderField(java.lang.String)> github-api-master\target\classes
<okhttp3.internal.huc.OkHttpURLConnection: java.lang.String getHeaderField(java.lang.String)> Repositories\com\squareup\okhttp3\okhttp-urlconnection\3.12.3\okhttp-urlconnection-3.12.3.jar
<okhttp3.internal.http.StatusLine: okhttp3.internal.http.StatusLine get(okhttp3.Response)>

The above missing methods are actually referenced by github-api-master, which will cause “NoSuchMethodErrors” at runtime.

Suggested fixing solutions:

  1. Upgrade dependency com.squareup.okhttp3:okhttp-urlconnection from 3.12.3 to 4.4.1. Because one conflicting library version com.squareup.okhttp3:okhttp:3.12.3 is transitively introduced by com.squareup.okhttp3:okhttp-urlconnection:3.12.3. Upgrading dependency com.squareup.okhttp3:okhttp-urlconnection from 3.12.3 to 4.4.1 can solve this dependency conflict.
  2. Change dependency com.squareup.okhttp3:okhttp from 4.4.1 to 3.12.3.

Please let me know which solution do you prefer? I can submit a PR to fix it.

Thank you very much for your attention.
Best regards,

Dependency tree----

click for details
[INFO] org.kohsuke:github-api:jar:1.117-SNAPSHOT
[INFO] +- org.apache.commons:commons-lang3:jar:3.9:compile
[INFO] +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] +- org.hamcrest:hamcrest-core:jar:2.2:test
[INFO] | \- (org.hamcrest:hamcrest:jar:2.2:test - omitted for duplicate)
[INFO] +- org.hamcrest:hamcrest-library:jar:2.2:test
[INFO] | \- (org.hamcrest:hamcrest-core:jar:2.2:test - omitted for duplicate)
[INFO] +- junit:junit:jar:4.13:test
[INFO] | \- (org.hamcrest:hamcrest-core:jar:1.3:test - omitted for conflict with 2.2)
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.10.2:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.2:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.10.2:compile
[INFO] +- commons-io:commons-io:jar:2.4:compile
[INFO] +- com.infradna.tool:bridge-method-annotation:jar:1.18:compile
[INFO] | \- org.jenkins-ci:annotation-indexer:jar:1.4:compile
[INFO] +- commons-fileupload:commons-fileupload:jar:1.4:test
[INFO] | \- (commons-io:commons-io:jar:2.2:test - omitted for conflict with 2.4)
[INFO] +- commons-discovery:commons-discovery:jar:0.5:test
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:test
[INFO] +- org.kohsuke.stapler:stapler:jar:1.260:test
[INFO] | +- javax.annotation:javax.annotation-api:jar:1.2:test
[INFO] | +- (commons-discovery:commons-discovery:jar:0.4:test - omitted for conflict with 0.5)
[INFO] | +- commons-beanutils:commons-beanutils:jar:1.9.2:test
[INFO] | | +- (commons-logging:commons-logging:jar:1.1.1:test - omitted for duplicate)
[INFO] | | \- commons-collections:commons-collections:jar:3.2.1:test
[INFO] | +- (commons-io:commons-io:jar:2.4:test - omitted for duplicate)
[INFO] | +- (commons-logging:commons-logging:jar:1.2:test - omitted for conflict with 1.1.1)
[INFO] | +- commons-codec:commons-codec:jar:1.9:test
[INFO] | +- org.jvnet.localizer:localizer:jar:1.7:test
[INFO] | +- org.kohsuke.stapler:json-lib:jar:2.4-jenkins-2:test
[INFO] | | +- (commons-beanutils:commons-beanutils:jar:1.8.0:test - omitted for conflict with 1.9.2)
[INFO] | | +- (commons-collections:commons-collections:jar:3.2.1:test - omitted for duplicate)
[INFO] | | +- commons-lang:commons-lang:jar:2.5:test
[INFO] | | +- (commons-logging:commons-logging:jar:1.1.1:test - omitted for duplicate)
[INFO] | | \- net.sf.ezmorph:ezmorph:jar:1.0.6:test
[INFO] | | \- (commons-lang:commons-lang:jar:2.3:test - omitted for conflict with 2.5)
[INFO] | +- org.jvnet:tiger-types:jar:2.2:test
[INFO] | +- com.google.guava:guava:jar:11.0.1:test
[INFO] | | \- (com.google.code.findbugs:jsr305:jar:1.3.9:test - omitted for conflict with 2.0.1)
[INFO] | +- org.kohsuke:asm5:jar:5.0.1:test
[INFO] | +- (commons-fileupload:commons-fileupload:jar:1.3.1-jenkins-2:test - omitted for conflict with 1.4)
[INFO] | +- com.google.code.findbugs:jsr305:jar:2.0.1:test
[INFO] | +- com.jcraft:jzlib:jar:1.1.3:test
[INFO] | \- (com.github.spotbugs:spotbugs-annotations:jar:3.1.12:test - omitted for conflict with 4.1.1)
[INFO] +- org.kohsuke.stapler:stapler-jetty:jar:1.1:test
[INFO] | +- (org.kohsuke.stapler:stapler:jar:1.177:test - omitted for conflict with 1.260)
[INFO] | \- org.eclipse.jetty:jetty-servlet:jar:7.5.4.v20111024:test
[INFO] | \- org.eclipse.jetty:jetty-security:jar:7.5.4.v20111024:test
[INFO] | \- org.eclipse.jetty:jetty-server:jar:7.5.4.v20111024:test
[INFO] | +- javax.servlet:servlet-api:jar:2.5:test
[INFO] | +- org.eclipse.jetty:jetty-continuation:jar:7.5.4.v20111024:test
[INFO] | \- org.eclipse.jetty:jetty-http:jar:7.5.4.v20111024:test
[INFO] | \- org.eclipse.jetty:jetty-io:jar:7.5.4.v20111024:test
[INFO] | \- org.eclipse.jetty:jetty-util:jar:7.5.4.v20111024:test
[INFO] +- org.eclipse.jgit:org.eclipse.jgit:jar:5.7.0.202003110725-r:test
[INFO] | +- com.jcraft:jsch:jar:0.1.55:test
[INFO] | +- (com.jcraft:jzlib:jar:1.1.1:test - omitted for conflict with 1.1.3)
[INFO] | +- com.googlecode.javaewah:JavaEWAH:jar:1.1.7:test
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.2:test
[INFO] | +- org.bouncycastle:bcpg-jdk15on:jar:1.64:test
[INFO] | | \- (org.bouncycastle:bcprov-jdk15on:jar:1.64:test - omitted for duplicate)
[INFO] | +- org.bouncycastle:bcprov-jdk15on:jar:1.64:test
[INFO] | \- org.bouncycastle:bcpkix-jdk15on:jar:1.64:test
[INFO] | \- (org.bouncycastle:bcprov-jdk15on:jar:1.64:test - omitted for duplicate)
[INFO] +- com.squareup.okio:okio:jar:2.5.0:compile
[INFO] | +- org.jetbrains.kotlin:kotlin-stdlib:jar:1.3.70:compile
[INFO] | | +- (org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.3.70:compile - omitted for duplicate)
[INFO] | | \- org.jetbrains:annotations:jar:13.0:compile
[INFO] | \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.3.70:compile
[INFO] +- com.squareup.okhttp3:okhttp:jar:4.4.1:compile
[INFO] | +- (com.squareup.okio:okio:jar:2.4.3:compile - omitted for conflict with 2.5.0)
[INFO] | \- (org.jetbrains.kotlin:kotlin-stdlib:jar:1.3.61:compile - omitted for conflict with 1.3.70)
[INFO] +- com.squareup.okhttp3:okhttp-urlconnection:jar:3.12.3:compile
[INFO] | \- (com.squareup.okhttp3:okhttp:jar:3.12.3:compile - omitted for conflict with 4.4.1)
[INFO] +- com.squareup.okhttp:okhttp-urlconnection:jar:2.7.5:compile
[INFO] | \- com.squareup.okhttp:okhttp:jar:2.7.5:compile
[INFO] | \- (com.squareup.okio:okio:jar:1.6.0:compile - omitted for conflict with 2.5.0)
[INFO] +- org.kohsuke:wordnet-random-name:jar:1.3:test
[INFO] +- org.mockito:mockito-core:jar:3.4.6:test
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.10.13:test
[INFO] | +- net.bytebuddy:byte-buddy-agent:jar:1.10.13:test
[INFO] | \- org.objenesis:objenesis:jar:2.6:test
[INFO] +- com.github.spotbugs:spotbugs-annotations:jar:4.1.1:provided
[INFO] | \- (com.google.code.findbugs:jsr305:jar:3.0.2:provided - omitted for conflict with 2.0.1)
[INFO] +- com.github.tomakehurst:wiremock-jre8-standalone:jar:2.27.1:test
[INFO] \- com.google.code.gson:gson:jar:2.8.6:test
@Bing-ok
Copy link
Author

Bing-ok commented Aug 15, 2020

Could you help me review this issue? 👍 Thanks! @bitwiseman

@bitwiseman
Copy link
Member

bitwiseman commented Aug 17, 2020

@Bing-ok

Suggested fixing solutions:

  1. Upgrade dependency com.squareup.okhttp3:okhttp-urlconnection from 3.12.3 to 4.4.1. Because one conflicting library version com.squareup.okhttp3:okhttp:3.12.3 is transitively introduced by com.squareup.okhttp3:okhttp-urlconnection:3.12.3. Upgrading dependency com.squareup.okhttp3:okhttp-urlconnection from 3.12.3 to 4.4.1 can solve this dependency conflict.
  2. Change dependency com.squareup.okhttp3:okhttp from 4.4.1 to 3.12.3.

Neither of these. This setting is by design.

These are optional dependencies. com.squareup.okhttp3:okhttp-urlconnection is deprecated, but retained for compatibility.

If a down stream project wants to use com.squareup.okhttp3:okhttp-urlconnection they can do so my forcing com.squareup.okhttp3:okhttp in their project to 3.12.3 (using dependencyManagment).

Option 1 would break compatibility, option 2 would downgrade behavior.

@Bing-ok
Copy link
Author

Bing-ok commented Aug 20, 2020

Thanks for your support! What do you suggest to solve this problem?

@bitwiseman
Copy link
Member

@Bing-ok
Dependency management allows you to exclude dependencies or force them to versions you want.
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#dependency-management

I assume that you are trying to use com.squareup.okhttp3:okhttp-urlconnection. I strongly suggest that you use the Client class of com.squareup.okhttp3:okhttp if possible. com.squareup.okhttp3:okhttp-urlconnection is deprecated and unsupported.

Putting that aside, here's how you can fix the dependency tree problem you're seeing.

You can do this:

  <dependencies>
     <dependency>
       <groupId>com.squareup.okhttp3</groupId>
       <artifactId>okhttp-urlconnection</artifactId>
       <version>3.12.12</version>
    </dependency>
    <dependency>
      <groupId>org.kohsuke</groupId>
      <artifactId>github-api</artifactId>
      <version>1.116</version>
      <exclusions>
        <exclusion>
          <groupId>com.squareup.okhttp3</groupId>
          <artifactId>okhttp</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.squareup.okhttp3</groupId>
          <artifactId>okhttp-urlconnection</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>

Or you can something like this:

  <dependencyManagement>
    <dependencies>
       <dependency>
         <groupId>com.squareup.okhttp3</groupId>
         <artifactId>okhttp</artifactId>
         <version>3.12.12</version>
      </dependency>
       <dependency>
         <groupId>com.squareup.okhttp3</groupId>
         <artifactId>okhttp-urlconnection</artifactId>
         <version>3.12.12</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
     <dependency>
       <groupId>com.squareup.okhttp3</groupId>
       <artifactId>okhttp-urlconnection</artifactId>
    </dependency>
    <dependency>
      <groupId>org.kohsuke</groupId>
      <artifactId>github-api</artifactId>
      <version>1.116</version>
    </dependency>
  </dependencies>

@bitwiseman
Copy link
Member

Closing as not an issue, but I'm happy to continue discussing as needed. Please consider joining the gitter.im channel to ask questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants