googleads / google-ads-java

Google Ads API Client Library for Java
Apache License 2.0
171 stars 177 forks source link

Correct the classpath of your application so that it contains a single, compatible version of com.google.api.gax.core.GoogleCredentialsProvider$Builder #727

Closed balaYYYYYYYY closed 1 year ago

balaYYYYYYYY commented 1 year ago

I encountered this error while running the project, but I did not conflict with this library. Please help me see what the reason is

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

com.google.ads.googleads.v14.services.stub.KeywordPlanIdeaServiceStubSettings.defaultCredentialsProviderBuilder(KeywordPlanIdeaServiceStubSettings.java:253)

The following method did not exist:

com.google.api.gax.core.GoogleCredentialsProvider$Builder.setUseJwtAccessWithScope(Z)Lcom/google/api/gax/core/GoogleCredentialsProvider$Builder;

The method's class, com.google.api.gax.core.GoogleCredentialsProvider$Builder, is available from the following locations:

jar:file:/D:/Program/Java/maven/LocalRepository/com/google/api/gax/1.60.1/gax-1.60.1.jar!/com/google/api/gax/core/GoogleCredentialsProvider$Builder.class

The class hierarchy was loaded from the following locations:

com.google.api.gax.core.GoogleCredentialsProvider.Builder: file:/D:/Program/Java/maven/LocalRepository/com/google/api/gax/1.60.1/gax-1.60.1.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of com.google.api.gax.core.GoogleCredentialsProvider$Builder

com.google.api-ads google-ads 26.0.0

this is my dependency tree

[INFO] +- com.google.protobuf:protobuf-java:jar:3.22.2:compile
[INFO] +- com.google.protobuf:protobuf-java-util:jar:3.22.2:compile
[INFO] |  +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] |  +- com.google.code.gson:gson:jar:2.8.7:compile
[INFO] |  +- com.google.errorprone:error_prone_annotations:jar:2.11.0:compile
[INFO] |  \- com.google.j2objc:j2objc-annotations:jar:1.3:compile
[INFO] +- com.google.guava:guava:jar:32.1.2-jre:compile
[INFO] |  +- com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] |  +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] |  \- org.checkerframework:checker-qual:jar:3.33.0:compile
[INFO] +- com.google.api-ads:google-ads:jar:26.0.0:compile
[INFO] |  +- com.google.api:gax:jar:1.60.1:compile
[INFO] |  |  +- org.threeten:threetenbp:jar:1.5.0:compile
[INFO] |  |  +- com.google.api:api-common:jar:1.10.1:compile
[INFO] |  |  \- io.opencensus:opencensus-api:jar:0.24.0:compile
[INFO] |  |     \- io.grpc:grpc-context:jar:1.34.1:compile
[INFO] |  +- com.google.api:gax-grpc:jar:1.60.1:compile
[INFO] |  |  +- io.grpc:grpc-auth:jar:1.34.1:compile
[INFO] |  |  +- com.google.api.grpc:proto-google-common-protos:jar:2.0.1:compile
[INFO] |  |  +- io.grpc:grpc-netty-shaded:jar:1.34.1:compile
[INFO] |  |  |  \- io.grpc:grpc-core:jar:1.34.1:compile
[INFO] |  |  |     +- com.google.android:annotations:jar:4.1.1.4:runtime
[INFO] |  |  |     \- io.perfmark:perfmark-api:jar:0.19.0:runtime
[INFO] |  |  \- io.grpc:grpc-alts:jar:1.34.1:compile
[INFO] |  |     +- io.grpc:grpc-grpclb:jar:1.34.1:compile
[INFO] |  |     +- org.apache.commons:commons-lang3:jar:3.10:compile
[INFO] |  |     \- org.conscrypt:conscrypt-openjdk-uber:jar:2.5.1:compile
[INFO] |  +- io.grpc:grpc-stub:jar:1.34.1:compile
[INFO] |  |  +- io.grpc:grpc-api:jar:1.34.1:compile
[INFO] |  |  \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.18:runtime
[INFO] |  +- io.grpc:grpc-protobuf:jar:1.34.1:compile
[INFO] |  |  \- io.grpc:grpc-protobuf-lite:jar:1.34.1:compile
[INFO] |  +- com.google.auth:google-auth-library-oauth2-http:jar:0.22.1:compile
[INFO] |  |  +- com.google.http-client:google-http-client:jar:1.38.0:compile
[INFO] |  |  |  +- org.apache.httpcomponents:httpclient:jar:4.5.13:compile
[INFO] |  |  |  |  \- commons-codec:commons-codec:jar:1.14:compile
[INFO] |  |  |  +- org.apache.httpcomponents:httpcore:jar:4.4.14:compile
[INFO] |  |  |  \- io.opencensus:opencensus-contrib-http-util:jar:0.24.0:compile
[INFO] |  |  \- com.google.http-client:google-http-client-jackson2:jar:1.38.0:compile
[INFO] |  |     \- com.fasterxml.jackson.core:jackson-core:jar:2.11.4:compile
[INFO] |  +- com.google.auth:google-auth-library-credentials:jar:0.22.1:compile
[INFO] |  +- com.google.api-ads:google-ads-codegen:jar:26.0.0:compile
[INFO] |  |  +- com.google.api-ads:google-ads-stubs-lib:jar:26.0.0:compile
[INFO] |  |  +- com.google.api-ads:google-ads-stubs-v12:jar:26.0.0:compile
[INFO] |  |  +- com.google.api-ads:google-ads-stubs-v13:jar:26.0.0:compile
[INFO] |  |  +- com.google.api-ads:google-ads-stubs-v14:jar:26.0.0:compile
[INFO] |  |  \- com.squareup:javapoet:jar:1.11.1:runtime
[INFO] |  +- com.google.auto.service:auto-service:jar:1.0.1:runtime
[INFO] |  |  +- com.google.auto.service:auto-service-annotations:jar:1.0.1:runtime
[INFO] |  |  \- com.google.auto:auto-common:jar:1.2:runtime
[INFO] |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO] |  \- com.google.auto.value:auto-value-annotations:jar:1.7.4:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.3.12.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.3.12.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:2.3.12.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.3.12.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.3.12.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.13.3:compile
[INFO] |  |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.13.3:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.30:compile
[INFO] |  |  +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] |  |  +- org.springframework:spring-core:jar:5.2.15.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-jcl:jar:5.2.15.RELEASE:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.26:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.3.12.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.11.4:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.11.4:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.11.4:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.11.4:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.11.4:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.3.12.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.46:compile
[INFO] |  |  +- org.glassfish:jakarta.el:jar:3.0.3:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.46:compile
[INFO] |  +- org.springframework:spring-web:jar:5.2.15.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:5.2.15.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.2.15.RELEASE:compile
[INFO] |     +- org.springframework:spring-aop:jar:5.2.15.RELEASE:compile
[INFO] |     +- org.springframework:spring-context:jar:5.2.15.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:5.2.15.RELEASE:compile
[INFO] \- com.beust:jcommander:jar:1.78:compile
jradcliff commented 1 year ago

Hi,

I'm a bit perplexed about the dependencies you're seeing in your tree. For example, your output shows the following:

+- com.google.api-ads:google-ads:jar:26.0.0:compile
|  +- com.google.api:gax:jar:1.60.1:compile
|  |  +- org.threeten:threetenbp:jar:1.5.0:compile
|  |  +- com.google.api:api-common:jar:1.10.1:compile
|  |  \- io.opencensus:opencensus-api:jar:0.24.0:compile
|  |     \- io.grpc:grpc-context:jar:1.34.1:compile
|  +- com.google.api:gax-grpc:jar:1.60.1:compile

Notice that the com.google.api:gax and com.google.api:gax-grpc dependencies are both resolving to 1.60.1, which is a very old version of those libraries.

In contrast, I created a simple project with just two dependencies:

com.google.guava:guava:31.1-jre
com.google.api-ads:google-ads:26.0.0

When I look at the dependency tree for the simple project, it's resolving to version 2.29.0 of gax and gax-grpc, as expected.

--- com.google.api-ads:google-ads:26.0.0
     +--- com.google.api:gax -> 2.29.0
     +--- com.google.api:gax-grpc -> 2.29.0
...

I see a similar difference in the io.grpc:* dependencies. In your project it's resolving to 1.34.1, but in the simple project it's resolving to 1.55.1.

In both cases, the dependencies in my simple project match what is shown on Maven:

https://central.sonatype.com/artifact/com.google.api-ads/google-ads/26.0.0/dependencies

This is all quite strange, and suggests that your local Maven repository may be corrupted in some way. Can you try renaming your local repository temporarily and building again to see if the dependency tree changes?

Thanks, Josh

balaYYYYYYYY commented 1 year ago

I found the issue, it seems to be caused by the lower version of my Spring Cloud. However, I can't upgrade the Spring Cloud version of my project, so I have to start a new service.

jradcliff commented 1 year ago

You could try using the shaded version of the library as described at https://developers.google.com/google-ads/api/docs/client-libs/java/advanced-usage#shadow_dependencies.