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

NoSuchMethodError: old Apache library loaded in Gradle build environment #2183

Closed
edobry opened this issue Dec 3, 2019 · 15 comments · Fixed by #2213
Closed

NoSuchMethodError: old Apache library loaded in Gradle build environment #2183

edobry opened this issue Dec 3, 2019 · 15 comments · Fixed by #2213

Comments

@edobry
Copy link

edobry commented Dec 3, 2019

Environment:

  • Jib version: 1.8.0
  • Build tool: Gradle 5.4.1
  • OS: OSX 10.14.6

Description of the issue:
When trying to run gradle jibDockerBuild with the jib gradle plugin v1.8.0, I got a very confusing error message with no results on Google:

> com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException: org.apache.http.client.config.RequestConfig$Builder.setNormalizeUri(Z)Lorg/apache/http/client/config/RequestConfig$Builder;

Expected behavior:
When running the same command with the jib plugin v1.7.0, I get this much more helpful error message:

Steps to reproduce:

1. Kill the docker daemon
2. Add the jib gradle plugin v1.8.0 to a gradle build
3. Run gradle jibDockerBuild

jib-gradle-plugin Configuration:

plugins {
    id 'com.google.cloud.tools.jib' version '1.8.0'
}
@loosebazooka
Copy link
Member

loosebazooka commented Dec 4, 2019

I think, this is because we upgraded the http client, but your build is probably configured to pull in an earlier version.

Can you include the output of ./gradlew buildenv so we can potentially see where this missing method issue is coming from?

Ideally you would see a dependency for org.apache.httpcomponents:httpclient:4.5.5(EDIT: I think I was looking at an old version of our code, you want 4.5.10) but I think something else is overriding this (perhaps in a parent buildscript)? It should be noted that even if a child buildscript is pulling in a dependency, it cannot override the version pulled in at the parent level: https://discuss.gradle.org/t/version-is-root-build-gradle-buildscript-is-overriding-subproject-buildscript-dependency-versions/20746

@edobry
Copy link
Author

edobry commented Dec 4, 2019

output of gradle buildenv:

+--- io.freefair.lombok:io.freefair.lombok.gradle.plugin:4.1.5
|    \--- io.freefair.gradle:lombok-plugin:4.1.5
+--- org.springframework.boot:org.springframework.boot.gradle.plugin:2.1.3.RELEASE
|    \--- org.springframework.boot:spring-boot-gradle-plugin:2.1.3.RELEASE
|         +--- org.springframework.boot:spring-boot-loader-tools:2.1.3.RELEASE
|         |    +--- org.springframework:spring-core:5.1.5.RELEASE
|         |    |    \--- org.springframework:spring-jcl:5.1.5.RELEASE
|         |    \--- org.apache.commons:commons-compress:1.18 -> 1.19
|         +--- io.spring.gradle:dependency-management-plugin:1.0.6.RELEASE
|         \--- org.apache.commons:commons-compress:1.18 -> 1.19
+--- org.unbroken-dome.test-sets:org.unbroken-dome.test-sets.gradle.plugin:2.1.1
|    \--- org.unbroken-dome.gradle-plugins:gradle-testsets-plugin:2.1.1
|         +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.11
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11
|         |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.11
|         |    |    \--- org.jetbrains:annotations:13.0
|         |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11
|         |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
|         \--- org.jetbrains.kotlin:kotlin-reflect:1.3.11
|              \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.11 (*)
\--- com.google.cloud.tools.jib:com.google.cloud.tools.jib.gradle.plugin:1.8.0
     \--- gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:1.8.0
          +--- com.google.http-client:google-http-client:1.33.0
          |    +--- org.apache.httpcomponents:httpclient:4.5.10
          |    |    +--- org.apache.httpcomponents:httpcore:4.4.12
          |    |    +--- commons-logging:commons-logging:1.2
          |    |    \--- commons-codec:commons-codec:1.11
          |    +--- org.apache.httpcomponents:httpcore:4.4.12
          |    +--- com.google.code.findbugs:jsr305:3.0.2
          |    +--- com.google.guava:guava:28.1-android -> 28.1-jre
          |    |    +--- com.google.guava:failureaccess:1.0.1
          |    |    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
          |    |    +--- com.google.code.findbugs:jsr305:3.0.2
          |    |    +--- org.checkerframework:checker-qual:2.8.1
          |    |    +--- com.google.errorprone:error_prone_annotations:2.3.2
          |    |    +--- com.google.j2objc:j2objc-annotations:1.3
          |    |    \--- org.codehaus.mojo:animal-sniffer-annotations:1.18
          |    +--- com.google.j2objc:j2objc-annotations:1.3
          |    +--- io.opencensus:opencensus-api:0.24.0
          |    |    \--- io.grpc:grpc-context:1.22.1
          |    \--- io.opencensus:opencensus-contrib-http-util:0.24.0
          |         +--- io.opencensus:opencensus-api:0.24.0 (*)
          |         \--- com.google.guava:guava:26.0-android -> 28.1-jre (*)
          +--- com.google.http-client:google-http-client-apache-v2:1.33.0
          |    +--- com.google.http-client:google-http-client:1.33.0 (*)
          |    +--- org.apache.httpcomponents:httpclient:4.5.10 (*)
          |    \--- org.apache.httpcomponents:httpcore:4.4.12
          +--- com.google.auth:google-auth-library-oauth2-http:0.18.0
          |    +--- com.google.auto.value:auto-value-annotations:1.6.6
          |    +--- com.google.code.findbugs:jsr305:3.0.2
          |    +--- com.google.auth:google-auth-library-credentials:0.18.0
          |    +--- com.google.http-client:google-http-client:1.32.1 -> 1.33.0 (*)
          |    +--- com.google.http-client:google-http-client-jackson2:1.32.1
          |    |    +--- com.google.http-client:google-http-client:1.32.1 -> 1.33.0 (*)
          |    |    \--- com.fasterxml.jackson.core:jackson-core:2.9.9 -> 2.9.10
          |    \--- com.google.guava:guava:28.1-android -> 28.1-jre (*)
          +--- org.apache.commons:commons-compress:1.19
          +--- com.google.guava:guava:28.1-jre (*)
          +--- com.fasterxml.jackson.core:jackson-databind:2.9.10
          |    +--- com.fasterxml.jackson.core:jackson-annotations:2.9.10
          |    \--- com.fasterxml.jackson.core:jackson-core:2.9.10
          \--- org.ow2.asm:asm:7.2

doesn't seem like an older version is being pulled in, but I might have missed something

@chanseokoh
Copy link
Member

I cannot reproduce it. I still get the same error message with 1.8.0.

> com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException: 'docker load' command failed with error: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I think upgrading to 1.8.0 changed your build env to cause the new error. But it's not clear where it's coming from. Could you do gradlew --stacktrace jibDockerBuild to get the stack trace?

@loosebazooka
Copy link
Member

Also, just so I'm sure: Is this a single project? No parent build.gradle, settings.gradle?

@edobry
Copy link
Author

edobry commented Dec 4, 2019

here is the relevant portion of the stacktrace:

Caused by: java.lang.NoSuchMethodError: org.apache.http.client.config.RequestConfig$Builder.setNormalizeUri(Z)Lorg/apache/http/client/config/RequestConfig$Builder;
        at com.google.api.client.http.apache.v2.ApacheHttpRequest.<init>(ApacheHttpRequest.java:43)
        at com.google.api.client.http.apache.v2.ApacheHttpTransport.buildRequest(ApacheHttpTransport.java:179)
        at com.google.api.client.http.apache.v2.ApacheHttpTransport.buildRequest(ApacheHttpTransport.java:58)
        at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:872)
        at com.google.cloud.tools.jib.http.FailoverHttpClient.call(FailoverHttpClient.java:309)
        at com.google.cloud.tools.jib.http.FailoverHttpClient.call(FailoverHttpClient.java:237)
        at com.google.cloud.tools.jib.registry.RegistryEndpointCaller.call(RegistryEndpointCaller.java:139)
        at com.google.cloud.tools.jib.registry.RegistryEndpointCaller.call(RegistryEndpointCaller.java:115)
        at com.google.cloud.tools.jib.registry.RegistryClient.callRegistryEndpoint(RegistryClient.java:473)
        at com.google.cloud.tools.jib.registry.RegistryClient.pullManifest(RegistryClient.java:303)
        at com.google.cloud.tools.jib.registry.RegistryClient.pullManifest(RegistryClient.java:307)
        at com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.pullBaseImage(PullBaseImageStep.java:205)
        at com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.call(PullBaseImageStep.java:126)
        at com.google.cloud.tools.jib.builder.steps.PullBaseImageStep.call(PullBaseImageStep.java:59)

and, to clarify, this is a subproject, but the parent project has no relevant dependencies. I'm also not upgrading, but adding jib for the first time. Downgrading to 1.7.0 and starting Docker fixes the issue, but I'm not able to get it to work with 1.8.0 at all.

@loosebazooka
Copy link
Member

parent project has no relevant dependencies

^^^ Sometimes this doesn't hold true, and buildEnv doesn't give you the right data. Are you applying any plugins in your parent?

Does your ./gradlew buildEnv show anything when run on the parent project?

@chanseokoh
Copy link
Member

@edobry have you figured out something? Did ./gradlew buildEnv on the parent project reveal anything? This is certainly that an old version of the Apache library is being used. I'm pretty sure whether Docker is running or not doesn't matter. This should be happening all the time with 1.8.0 in your build environment.

@edobry
Copy link
Author

edobry commented Dec 5, 2019

I ran gradle buildEnv on the parent project and indeed found a reference to an older version of that library (truncated deptreee):

|    \--- org.jfrog.buildinfo:build-info-extractor-gradle:4.11.0
|         +--- org.jfrog.buildinfo:build-info-extractor:2.13.14
|         |    \--- org.jfrog.buildinfo:build-info-client:2.13.14
|         |         +--- org.apache.httpcomponents:httpclient:4.5.2

I ended up fixing my issue by downgrading to 1.7.0, but how should this be properly resolved? Is there a way to isolate plugin dependencies?

@loosebazooka
Copy link
Member

loosebazooka commented Dec 5, 2019

I think you can ask the parent to load in the jib plugin in the parent but not apply it (apply false), so the classpaths are correct?

plugins {
  id 'com.google.cloud.tools.jib' version '1.8.0' apply false
}

and then use the plugin in your subproject (you can omit the version since it's specified above)

plugins {
  id 'com.google.cloud.tools.jib
}

Can you see if that works? If not, there's the option of just adding the httpclient at the right version to the buildscript classpath in the root project.

@chanseokoh chanseokoh changed the title Error message regression in jib 1.8.0 NoSuchMethodError: old Apache library loaded in Gradle build environment Dec 5, 2019
@edobry
Copy link
Author

edobry commented Dec 5, 2019

That did indeed fix the issue, thanks! May be useful to add this tip to documentation or troubleshooting.

@loosebazooka
Copy link
Member

loosebazooka commented Dec 5, 2019

Yeah gradle's buildscript classpath resolution can be a little problematic :(.

@jvmlet
Copy link

jvmlet commented Jan 2, 2020

That did indeed fix the issue, thanks! May be useful to add this tip to documentation or troubleshooting.

Would save me time if was present in README.

@Sineaggi
Copy link
Contributor

Sineaggi commented Jan 3, 2020

Unsure if this will help anyone, but we encountered this when using the Gradle Artifactory plugin. The version 2.8.5 was released as a fat jar, which meant that excluding the old apache http client did not exclude the classes (the plugin's pom file still contained artifactory's compile dependencies). The shadowed dependencies/classes were being loaded regardless, causing the NoSuchMethodError.

We were able to fix this by upgrading to 2.8.6.

@jvmlet
Copy link

jvmlet commented Jan 3, 2020

I also had this issue when combining with artifactory gradle plugin. The solution described above did the trick.

@loosebazooka
Copy link
Member

loosebazooka commented Jan 3, 2020

For those hitting this issue, we've added an FAQ explaining how to properly fix this in Gradle.

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

Successfully merging a pull request may close this issue.

5 participants