googleapis / google-cloud-java

Google Cloud Client Library for Java
https://cloud.google.com/java/docs/reference
Apache License 2.0
1.9k stars 1.07k forks source link

VertexAI with Java 21 fails with java.lang.IncompatibleClassChangeError: class com.google.cloud.vertexai.api.stub.PredictionServiceStubSettings overrides final method com.google.api.gax.rpc.StubSettings.getEndpoint()Ljava/lang/String; #10604

Closed bjornharvold closed 8 months ago

bjornharvold commented 8 months ago

Environment details

  1. Using the google-cloud-vertexai imported with maven com.google.cloud libraries-bom 26.34.0
  2. OS type and version: Mac OS 14.3.1
  3. Java version: 21

Steps to reproduce

  1. Execute code sample below

Code example

 try (VertexAI vertexAi = new VertexAI(MY_PROJECT, REGION, CREDENTIALS)) {
            GenerationConfig generationConfig =
                    GenerationConfig.newBuilder()
                            .setTemperature(0.8F)
                            .build();
            GenerativeModel model = new GenerativeModel("gemini-pro-vision", generationConfig, vertexAi);

            GenerateContentResponse response = model.generateContent("Tell me a joke!");
            System.out.println(response);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

Stack trace

java.lang.IncompatibleClassChangeError: class com.google.cloud.vertexai.api.stub.PredictionServiceStubSettings overrides final method com.google.api.gax.rpc.StubSettings.getEndpoint()Ljava/lang/String;

    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1027)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
    at com.google.cloud.vertexai.api.PredictionServiceSettings$Builder.createDefault(PredictionServiceSettings.java:280)
    at com.google.cloud.vertexai.api.PredictionServiceSettings$Builder.access$000(PredictionServiceSettings.java:261)
    at com.google.cloud.vertexai.api.PredictionServiceSettings.newBuilder(PredictionServiceSettings.java:237)
    at com.google.cloud.vertexai.VertexAI.getPredictionServiceClient(VertexAI.java:271)
    at com.google.cloud.vertexai.generativeai.GenerativeModel.generateContent(GenerativeModel.java:629)
    at com.google.cloud.vertexai.generativeai.GenerativeModel.generateContent(GenerativeModel.java:610)
    at com.google.cloud.vertexai.generativeai.GenerativeModel.generateContent(GenerativeModel.java:518)
    at org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient.doChatCompletion(VertexAiGeminiChatClient.java:450)
    at org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient.doChatCompletion(VertexAiGeminiChatClient.java:69)
    at org.springframework.ai.model.function.AbstractFunctionCallSupport.callWithFunctionSupport(AbstractFunctionCallSupport.java:124)
    at org.springframework.ai.vertexai.gemini.VertexAiGeminiChatClient.call(VertexAiGeminiChatClient.java:154)
    at travel.wink.ai.domain.vertexai.service.impl.VertexAiNativeServiceImpl.helloWorld(VertexAiNativeServiceImpl.java:43)
    at travel.wink.ai.domain.vertexai.VertexNativeServiceIntegrationTest.givenHelloWorld_whenVerifyingIntegration_thenVerify(VertexNativeServiceIntegrationTest.java:57)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
suztomo commented 8 months ago

This looks a typical dependency conflict on gax. Would you check the dependency graph of your project for gax version?

bjornharvold commented 8 months ago

Here are the results from mvn dependency:tree

[INFO] +- org.springframework.boot:spring-boot:jar:3.2.3:compile
[INFO] |  \- org.springframework:spring-core:jar:6.1.4:compile
[INFO] +- com.theokanning.openai-gpt3-java:service:jar:0.18.2:compile
[INFO] |  +- com.theokanning.openai-gpt3-java:client:jar:0.18.2:compile
[INFO] |  |  \- com.theokanning.openai-gpt3-java:api:jar:0.18.2:compile
[INFO] |  |     \- com.knuddels:jtokkit:jar:0.5.1:compile
[INFO] |  +- com.squareup.retrofit2:retrofit:jar:2.9.0:compile
[INFO] |  |  \- com.squareup.okhttp3:okhttp:jar:4.12.0:compile
[INFO] |  |     +- com.squareup.okio:okio:jar:3.6.0:compile
[INFO] |  |     |  \- com.squareup.okio:okio-jvm:jar:3.6.0:compile
[INFO] |  |     |     \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.9.22:compile
[INFO] |  |     \- org.jetbrains.kotlin:kotlin-stdlib-jdk8:jar:1.9.22:compile
[INFO] |  |        +- org.jetbrains.kotlin:kotlin-stdlib:jar:1.9.22:compile
[INFO] |  |        |  \- org.jetbrains:annotations:jar:13.0:compile
[INFO] |  |        \- org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:1.9.22:compile
[INFO] |  +- com.squareup.retrofit2:adapter-rxjava2:jar:2.9.0:compile
[INFO] |  |  +- io.reactivex.rxjava2:rxjava:jar:2.0.0:compile
[INFO] |  |  \- org.reactivestreams:reactive-streams:jar:1.0.4:compile
[INFO] |  +- com.squareup.retrofit2:converter-jackson:jar:2.9.0:runtime
[INFO] |  \- com.kjetland:mbknor-jackson-jsonschema_2.12:jar:1.0.34:runtime
[INFO] |     +- org.scala-lang:scala-library:jar:2.12.8:runtime
[INFO] |     +- javax.validation:validation-api:jar:2.0.1.Final:runtime
[INFO] |     \- io.github.classgraph:classgraph:jar:4.8.21:runtime
[INFO] +- org.seleniumhq.selenium:selenium-java:jar:4.17.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-api:jar:4.17.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-chrome-driver:jar:4.17.0:compile
[INFO] |  |  +- com.google.auto.service:auto-service-annotations:jar:1.1.1:compile
[INFO] |  |  +- org.seleniumhq.selenium:selenium-chromium-driver:jar:4.17.0:compile
[INFO] |  |  +- org.seleniumhq.selenium:selenium-json:jar:4.17.0:compile
[INFO] |  |  \- org.seleniumhq.selenium:selenium-manager:jar:4.17.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-devtools-v119:jar:4.17.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-devtools-v120:jar:4.17.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-devtools-v121:jar:4.17.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-devtools-v85:jar:4.17.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-edge-driver:jar:4.17.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-firefox-driver:jar:4.17.0:compile
[INFO] |  |  \- org.seleniumhq.selenium:selenium-http:jar:4.17.0:compile
[INFO] |  |     \- dev.failsafe:failsafe:jar:3.3.2:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-ie-driver:jar:4.17.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-remote-driver:jar:4.17.0:compile
[INFO] |  |  +- com.google.guava:guava:jar:33.0.0-jre:compile
[INFO] |  |  |  +- com.google.guava:failureaccess:jar:1.0.2:compile
[INFO] |  |  |  +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] |  |  |  \- com.google.j2objc:j2objc-annotations:jar:2.8:compile
[INFO] |  |  +- io.opentelemetry.semconv:opentelemetry-semconv:jar:1.23.1-alpha:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-api:jar:1.31.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-context:jar:1.31.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-exporter-logging:jar:1.31.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-sdk-common:jar:1.31.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:jar:1.31.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:jar:1.31.0:compile
[INFO] |  |  |  \- io.opentelemetry:opentelemetry-api-events:jar:1.31.0-alpha:runtime
[INFO] |  |  +- io.opentelemetry:opentelemetry-sdk-trace:jar:1.31.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-sdk:jar:1.31.0:compile
[INFO] |  |  |  +- io.opentelemetry:opentelemetry-sdk-metrics:jar:1.31.0:compile
[INFO] |  |  |  |  \- io.opentelemetry:opentelemetry-extension-incubator:jar:1.31.0-alpha:runtime
[INFO] |  |  |  \- io.opentelemetry:opentelemetry-sdk-logs:jar:1.31.0:compile
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.14.12:compile
[INFO] |  |  \- org.seleniumhq.selenium:selenium-os:jar:4.17.0:compile
[INFO] |  |     \- org.apache.commons:commons-exec:jar:1.3:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-safari-driver:jar:4.17.0:compile
[INFO] |  \- org.seleniumhq.selenium:selenium-support:jar:4.17.0:compile
[INFO] +- io.github.bonigarcia:webdrivermanager:jar:5.6.3:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:2.0.12:compile
[INFO] |  +- com.google.code.gson:gson:jar:2.10.1:compile
[INFO] |  +- com.github.docker-java:docker-java:jar:3.3.4:compile
[INFO] |  |  +- com.github.docker-java:docker-java-core:jar:3.3.4:compile
[INFO] |  |  |  +- com.github.docker-java:docker-java-api:jar:3.3.4:compile
[INFO] |  |  |  \- org.bouncycastle:bcpkix-jdk18on:jar:1.76:compile
[INFO] |  |  |     \- org.bouncycastle:bcutil-jdk18on:jar:1.76:compile
[INFO] |  |  \- org.slf4j:jcl-over-slf4j:jar:2.0.12:compile
[INFO] |  +- com.github.docker-java:docker-java-transport-httpclient5:jar:3.3.4:compile
[INFO] |  |  +- com.github.docker-java:docker-java-transport:jar:3.3.4:compile
[INFO] |  |  \- net.java.dev.jna:jna:jar:5.13.0:compile
[INFO] |  +- org.brotli:dec:jar:0.1.2:compile
[INFO] |  \- org.apache.httpcomponents.client5:httpclient5:jar:5.2.3:compile
[INFO] |     +- org.apache.httpcomponents.core5:httpcore5:jar:5.2.4:compile
[INFO] |     \- org.apache.httpcomponents.core5:httpcore5-h2:jar:5.2.4:compile
[INFO] +- org.jsoup:jsoup:jar:1.17.2:compile
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.10.2:test
[INFO] |  +- org.opentest4j:opentest4j:jar:1.3.0:runtime
[INFO] |  +- org.junit.platform:junit-platform-commons:jar:1.10.2:runtime
[INFO] |  \- org.apiguardian:apiguardian-api:jar:1.1.2:compile
[INFO] +- org.springframework.boot:spring-boot-test:jar:3.2.3:test
[INFO] +- org.springframework:spring-test:jar:6.1.4:test
[INFO] +- org.htmlunit:htmlunit-xpath:jar:3.11.0:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.30:compile
[INFO] +- io.swagger.core.v3:swagger-annotations:jar:2.2.15:compile
[INFO] +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
[INFO] +- jakarta.inject:jakarta.inject-api:jar:2.0.1.MR:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.4.14:compile
[INFO] |  \- ch.qos.logback:logback-core:jar:1.4.14:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO] +- org.apache.commons:commons-collections4:jar:4.4:compile
[INFO] +- commons-io:commons-io:jar:2.11.0:compile
[INFO] +- commons-beanutils:commons-beanutils:jar:1.9.4:compile
[INFO] |  \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] +- org.apache.commons:commons-text:jar:1.10.0:compile
[INFO] +- io.sentry:sentry-logback:jar:7.6.0:compile
[INFO] |  \- io.sentry:sentry:jar:7.6.0:compile
[INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-properties:jar:2.15.4:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.15.4:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-core:jar:2.15.4:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-json-org:jar:2.15.4:compile
[INFO] |  \- org.json:json:jar:20231013:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.15.4:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.15.4:compile
[INFO] +- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.15.4:compile
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.15.4:compile
[INFO] +- org.zalando:jackson-datatype-money:jar:1.3.0:compile
[INFO] |  +- javax.money:money-api:jar:1.1:compile
[INFO] |  \- org.javamoney.moneta:moneta-core:jar:1.4.2:compile
[INFO] +- org.javamoney:moneta:pom:1.4.2:compile
[INFO] |  +- org.javamoney.moneta:moneta-convert:jar:1.4.2:compile
[INFO] |  +- org.javamoney.moneta:moneta-convert-imf:jar:1.4.2:compile
[INFO] |  +- org.javamoney.moneta:moneta-convert-ecb:jar:1.4.2:compile
[INFO] |  \- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] +- com.fasterxml.uuid:java-uuid-generator:jar:4.2.0:compile
[INFO] +- org.threeten:threeten-extra:jar:1.7.2:compile
[INFO] +- jakarta.validation:jakarta.validation-api:jar:3.0.2:compile
[INFO] +- org.hibernate.validator:hibernate-validator:jar:8.0.1.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.5.3.Final:compile
[INFO] |  \- com.fasterxml:classmate:jar:1.6.0:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.14:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.16:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.16.1:compile
[INFO] +- com.maxmind.geoip2:geoip2:jar:4.2.0:compile
[INFO] |  \- com.maxmind.db:maxmind-db:jar:3.1.0:compile
[INFO] +- io.dropwizard.metrics:metrics-core:jar:4.2.25:compile
[INFO] +- org.apache.commons:commons-fileupload2-jakarta-servlet6:jar:2.0.0-M2:compile
[INFO] |  \- org.apache.commons:commons-fileupload2-core:jar:2.0.0-M2:compile
[INFO] +- com.cloudinary:cloudinary-http45:jar:1.36.0:compile
[INFO] |  +- com.cloudinary:cloudinary-core:jar:1.36.0:compile
[INFO] |  \- org.apache.httpcomponents:httpmime:jar:4.5.13:compile
[INFO] +- org.dom4j:dom4j:jar:2.1.4:compile
[INFO] +- org.apache.poi:poi:jar:5.2.3:compile
[INFO] |  +- org.apache.commons:commons-math3:jar:3.6.1:compile
[INFO] |  +- com.zaxxer:SparseBitSet:jar:1.2:compile
[INFO] |  \- org.apache.logging.log4j:log4j-api:jar:2.21.1:compile
[INFO] +- org.apache.poi:poi-ooxml:jar:5.2.3:compile
[INFO] |  +- org.apache.poi:poi-ooxml-lite:jar:5.2.3:compile
[INFO] |  +- org.apache.xmlbeans:xmlbeans:jar:5.1.1:compile
[INFO] |  \- com.github.virtuald:curvesapi:jar:1.07:compile
[INFO] +- org.apache.pdfbox:pdfbox:jar:3.0.1:compile
[INFO] |  +- org.apache.pdfbox:pdfbox-io:jar:3.0.1:compile
[INFO] |  +- org.apache.pdfbox:fontbox:jar:3.0.1:compile
[INFO] |  \- org.junit.jupiter:junit-jupiter:jar:5.10.2:compile
[INFO] |     +- org.junit.jupiter:junit-jupiter-params:jar:5.10.2:compile
[INFO] |     \- org.junit.jupiter:junit-jupiter-engine:jar:5.10.2:runtime
[INFO] |        \- org.junit.platform:junit-platform-engine:jar:1.10.2:runtime
[INFO] +- com.github.vandeseer:easytable:jar:1.0.0:compile
[INFO] +- org.springframework.security:spring-security-core:jar:6.2.2:compile
[INFO] |  +- org.springframework.security:spring-security-crypto:jar:6.2.2:compile
[INFO] |  +- org.springframework:spring-beans:jar:6.1.4:compile
[INFO] |  +- org.springframework:spring-expression:jar:6.1.4:compile
[INFO] |  \- io.micrometer:micrometer-observation:jar:1.12.3:compile
[INFO] |     \- io.micrometer:micrometer-commons:jar:1.12.3:compile
[INFO] +- org.springframework:spring-aop:jar:6.1.4:compile
[INFO] +- org.aspectj:aspectjweaver:jar:1.9.21:compile
[INFO] +- org.springframework:spring-context:jar:6.1.4:compile
[INFO] +- org.springframework:spring-context-support:jar:6.1.4:compile
[INFO] +- org.springframework.retry:spring-retry:jar:2.0.5:compile
[INFO] +- org.springframework.security:spring-security-rsa:jar:1.1.1:compile
[INFO] |  \- org.bouncycastle:bcprov-jdk18on:jar:1.74:compile
[INFO] +- org.springframework:spring-oxm:jar:6.1.4:compile
[INFO] +- org.springframework.session:spring-session-data-mongodb:jar:3.2.1:compile
[INFO] |  +- org.springframework.data:spring-data-mongodb:jar:4.2.3:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:6.1.4:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:3.2.3:compile
[INFO] |  |  \- org.mongodb:mongodb-driver-core:jar:4.11.1:compile
[INFO] |  |     +- org.mongodb:bson:jar:4.11.1:compile
[INFO] |  |     \- org.mongodb:bson-record-codec:jar:4.11.1:runtime
[INFO] |  \- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] +- org.springframework.security:spring-security-web:jar:6.2.2:compile
[INFO] |  \- org.springframework:spring-web:jar:6.1.4:compile
[INFO] +- org.springframework.security:spring-security-config:jar:6.2.2:compile
[INFO] +- org.springframework.security:spring-security-messaging:jar:6.2.2:compile
[INFO] |  \- org.springframework:spring-messaging:jar:6.1.4:compile
[INFO] +- org.springframework.session:spring-session-core:jar:3.2.1:compile
[INFO] |  \- org.springframework:spring-jcl:jar:6.1.4:compile
[INFO] +- com.opencsv:opencsv:jar:5.9:compile
[INFO] +- org.apache.commons:commons-compress:jar:1.26.0:compile
[INFO] +- org.jasypt:jasypt:jar:1.9.3:compile
[INFO] +- org.jasypt:jasypt-springsecurity4:jar:1.9.3:compile
[INFO] +- org.jasypt:jasypt-spring4:jar:1.9.3:compile
[INFO] +- com.paypal.sdk:rest-api-sdk:jar:1.14.0:compile
[INFO] +- com.stripe:stripe-java:jar:23.5.0:compile
[INFO] +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.0:compile
[INFO] |  \- jakarta.activation:jakarta.activation-api:jar:2.1.2:compile
[INFO] +- com.sun.xml.bind:jaxb-impl:jar:4.0.2:compile
[INFO] |  \- com.sun.xml.bind:jaxb-core:jar:4.0.4:compile
[INFO] |     \- org.eclipse.angus:angus-activation:jar:2.0.1:runtime
[INFO] +- org.mapstruct:mapstruct:jar:1.6.0.Beta1:compile
[INFO] +- org.mapstruct.extensions.spring:mapstruct-spring-annotations:jar:1.1.0:compile
[INFO] +- org.mapstruct.extensions.spring:mapstruct-spring-extensions:jar:1.1.0:compile
[INFO] |  \- com.squareup:javapoet:jar:1.13.0:runtime
[INFO] \- com.github.ben-manes.caffeine:caffeine:jar:3.1.8:compile
[INFO]    +- org.checkerframework:checker-qual:jar:3.37.0:compile
[INFO]    \- com.google.errorprone:error_prone_annotations:jar:2.21.1:compile
suztomo commented 8 months ago

It's strange that I cannot find "gax" or "google-cloud-vertexai" in the dependency tree. Would you identify which artifact contains com.google.api.gax.rpc.StubSettings in your project? IntelliJ has "Navigate Class" action.

meltsufin commented 8 months ago

@ZhenyiQ

bjornharvold commented 8 months ago

Fail on my part. I ran dependency tree from the wrong branch.

gax is at 2.38.0

Here's the relevant part: We get the same error whether we use Spring AI dependency or only import VertexAI.

[INFO] |  \- org.springframework.ai:spring-ai-vertex-ai-gemini:jar:0.8.1-SNAPSHOT:compile
[INFO] |     \- com.google.cloud:google-cloud-vertexai:jar:0.6.0:compile
[INFO] |        +- io.grpc:grpc-api:jar:1.59.1:compile
[INFO] |        +- io.grpc:grpc-stub:jar:1.59.1:compile
[INFO] |        +- io.grpc:grpc-protobuf:jar:1.59.1:compile
[INFO] |        +- io.grpc:grpc-protobuf-lite:jar:1.59.1:runtime
[INFO] |        +- com.google.api:api-common:jar:2.21.0:compile
[INFO] |        +- com.google.auto.value:auto-value-annotations:jar:1.10.4:compile
[INFO] |        +- com.google.api.grpc:proto-google-common-protos:jar:2.29.0:compile
[INFO] |        +- com.google.api.grpc:proto-google-cloud-vertexai-v1:jar:0.6.0: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] |        +- com.google.j2objc:j2objc-annotations:jar:2.8:compile
[INFO] |        +- com.google.api:gax:jar:2.38.0:compile
[INFO] |        +- com.google.auth:google-auth-library-credentials:jar:1.20.0:compile
[INFO] |        +- io.opencensus:opencensus-api:jar:0.31.1:compile
[INFO] |        +- io.grpc:grpc-context:jar:1.59.1:compile
[INFO] |        +- com.google.auth:google-auth-library-oauth2-http:jar:1.20.0:compile
[INFO] |        +- com.google.api:gax-grpc:jar:2.38.0:compile
[INFO] |        +- io.grpc:grpc-inprocess:jar:1.59.1:compile
[INFO] |        +- io.grpc:grpc-core:jar:1.59.1:compile
[INFO] |        +- com.google.android:annotations:jar:4.1.1.4:runtime
[INFO] |        +- org.codehaus.mojo:animal-sniffer-annotations:jar:1.23:runtime
[INFO] |        +- io.grpc:grpc-alts:jar:1.59.1:compile
[INFO] |        +- io.grpc:grpc-grpclb:jar:1.59.1:compile
[INFO] |        +- org.conscrypt:conscrypt-openjdk-uber:jar:2.5.2:compile
[INFO] |        +- io.grpc:grpc-auth:jar:1.59.1:compile
[INFO] |        +- io.grpc:grpc-netty-shaded:jar:1.59.1:compile
[INFO] |        +- io.grpc:grpc-util:jar:1.59.1:runtime
[INFO] |        +- io.perfmark:perfmark-api:jar:0.27.0:runtime
[INFO] |        +- io.grpc:grpc-googleapis:jar:1.59.1:runtime
[INFO] |        +- io.grpc:grpc-xds:jar:1.59.1:runtime
[INFO] |        +- io.opencensus:opencensus-proto:jar:0.2.0:runtime
[INFO] |        +- io.grpc:grpc-services:jar:1.59.1:runtime
[INFO] |        +- com.google.re2j:re2j:jar:1.7:runtime
[INFO] |        +- com.google.api:gax-httpjson:jar:2.38.0:compile
[INFO] |        +- com.google.http-client:google-http-client:jar:1.40.1:compile
[INFO] |        +- io.opencensus:opencensus-contrib-http-util:jar:0.31.1:compile
[INFO] |        +- com.google.http-client:google-http-client-gson:jar:1.43.3:compile
[INFO] |        +- com.google.protobuf:protobuf-java-util:jar:3.25.1:compile
[INFO] |        +- com.google.api.grpc:grpc-google-common-protos:jar:2.29.0:compile
[INFO] |        +- com.google.api.grpc:proto-google-iam-v1:jar:1.24.0:compile
[INFO] |        +- com.google.api.grpc:grpc-google-iam-v1:jar:1.24.0:compile
[INFO] |        \- org.threeten:threetenbp:jar:1.6.8:compile
suztomo commented 8 months ago

getEndpoint() method in StubSettings is available since gax v2.32.0. So 2.38.0 should be fine. I think you're getting a different com.google.api.gax.rpc.StubSettings definition from other place than gax. Would you check your IDE's "Navigate Class" action to see what JAR file contains com.google.api.gax.rpc.StubSettings?

Screenshot 2024-03-22 at 10 22 32 PM

org.springframework.ai:spring-ai-vertex-ai-gemini:jar:0.8.1-SNAPSHOT

That's new to me. Good to know. Thanks.

bjornharvold commented 8 months ago

Hi @suztomo

It's the same version. From IntelliJ: com.google.api:gax:2.38.0.jar

bjornharvold commented 8 months ago

Very outdated though seeing that I am working with a very active project. Maven repo says 2.46.1 is latest. 🤔

suztomo commented 8 months ago

I see. As per the Libraries BOM 26.34.0 release note https://github.com/googleapis/java-cloud-bom/releases/tag/v26.34.0 google-cloud-vertexai:0.6.0 was built and tested with gax 2.45.0. Would you explicitly declare gax 2.45.0 in your project?

suztomo commented 8 months ago

Using the google-cloud-vertexai imported with maven com.google.cloud libraries-bom 26.34.0

If your project correctly uses the Libraries BOM 26.34.0 (see instruction), then your dependency tree should show gax 2.45.0 already.

bjornharvold commented 8 months ago

Closing this. The issue was conflicting BOMs:

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>2023.0.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.google.cloud</groupId>
                <artifactId>spring-cloud-gcp-dependencies</artifactId>
                <version>5.0.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
vishalmysore commented 8 months ago

I am having the same issue , this is my BOM ,

<dependency>
                <groupId>com.konghq</groupId>
                <artifactId>unirest-java-bom</artifactId>
                <version>4.3.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <artifactId>libraries-bom</artifactId>
                <groupId>com.google.cloud</groupId>
                <scope>import</scope>
                <type>pom</type>
                <version>26.34.0</version>
         </dependency>

How did you resolve it?

vishalmysore commented 8 months ago

Never mind i fixed the problem by excluding Gax


  <dependency>
                <groupId>com.konghq</groupId>
                <artifactId>unirest-java-bom</artifactId>
                <version>4.3.0</version>
                <type>pom</type>
                <scope>import</scope>
                <exclusions>
                    <exclusion>
                        <groupId>com.google.api</groupId>
                        <artifactId>gax-grpc</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
suztomo commented 8 months ago

I've never heard of com.konghq:unirest-java-bom and I believe dependencyManagement does not take exclusions.

vishalmysore commented 8 months ago

exclusion worked , the gax-grpc was causing conflict

sbisht17 commented 7 months ago

I am also facing the similar issue while creating ReservationServiceClient client. Can anyone please help

Code Snippet

public static void main(String[] args) throws IOException { String projectId = "prod-resource-inventory-0001"; String location = "us-west-2"; quickStartSample(projectId, location); } public static void quickStartSample(String projectId, String location) throws IOException { try (ReservationServiceClient client = ReservationServiceClient.create()) { // list reservations in the project String parent = String.format("projects/%s/locations/%s", projectId, location); client .listReservations(parent) .iterateAll() .forEach(res -> System.out.println("Reservation resource name: " + res.getName()));

        // list capacity commitments in the project
        client
                .listCapacityCommitments(parent)
                .iterateAll()
                .forEach(
                        commitment ->
                                System.out.println("Capacity commitment resource name: " + commitment.getName()));
    }
}

Stack Trace

Exception in thread "main" java.lang.VerifyError: class com.google.cloud.bigquery.reservation.v1.stub.ReservationServiceStubSettings overrides final method com.google.api.gax.rpc.StubSettings.getEndpoint()Ljava/lang/String; at com.google.cloud.bigquery.reservation.v1.ReservationServiceSettings$Builder.createDefault(ReservationServiceSettings.java:305) at com.google.cloud.bigquery.reservation.v1.ReservationServiceSettings$Builder.access$000(ReservationServiceSettings.java:286) at com.google.cloud.bigquery.reservation.v1.ReservationServiceSettings.newBuilder(ReservationServiceSettings.java:263) at com.google.cloud.bigquery.reservation.v1.ReservationServiceClient.create(ReservationServiceClient.java:598)

Pom.xml

com.google.cloud google-cloud-bigqueryreservation 2.42.0
    <dependency>
        <groupId>com.konghq</groupId>
        <artifactId>unirest-java-bom</artifactId>
        <version>4.3.0</version>
        <type>pom</type>
        <scope>import</scope>
        <exclusions>
            <exclusion>
                <groupId>com.google.api</groupId>
                <artifactId>gax-grpc</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
com.google.cloud libraries-bom 26.34.0 pom import com.google.api.grpc gax 2.45.0
suztomo commented 7 months ago

@sbisht17 In Libraries BOM release 26.34.0 https://github.com/googleapis/java-cloud-bom/releases/tag/v26.34.0 here are library version you're interested in:

You can use mvn dependency:tree -Dverbose to see the dependency library versions of your project.

Manuel-Sphe commented 7 months ago

I have the this gax issue In release 26.34.0 it appears it's not using gax 2.45.0 :


./gradlew allDeps | grep gax
|         |    |    |    +--- com.google.api:gax:2.32.0
|         |    |    +--- com.google.api:gax:2.32.0 (*)
|         |    |    +--- com.google.api:gax-grpc:2.32.0
|         |    |    +--- com.google.api:gax-httpjson:2.32.0
|         |    |    |    +--- com.google.api:gax:2.32.0
|         |    |    +--- com.google.api:gax:2.32.0 (*)
|         |    |    +--- com.google.api:gax-grpc:2.32.0
|         |    |    +--- com.google.api:gax-httpjson:2.32.0
|         |    |    |    +--- com.google.api:gax:2.32.0
|         |    |    +--- com.google.api:gax:2.32.0 (*)
|         |    |    +--- com.google.api:gax-grpc:2.32.0
|         |    |    +--- com.google.api:gax-httpjson:2.32.0
     |    |    |    +--- com.google.api:gax:2.32.0
     |    |    +--- com.google.api:gax:2.32.0 (*)
     |    |    +--- com.google.api:gax-grpc:2.32.0
     |    |    +--- com.google.api:gax-httpjson:2.32.0
     |    |    |    +--- com.google.api:gax:2.32.0
     |    |    +--- com.google.api:gax:2.32.0 (*)
     |    |    +--- com.google.api:gax-grpc:2.32.0
     |    |    +--- com.google.api:gax-httpjson:2.32.0
     |    |    |    +--- com.google.api:gax:2.32.0
     |    |    +--- com.google.api:gax:2.32.0 (*)
     |    |    +--- com.google.api:gax-grpc:2.32.0
     |    |    +--- com.google.api:gax-httpjson:2.32.0
|    |    |    |    +--- com.google.api:gax:2.32.0
|    |    |    +--- com.google.api:gax:2.32.0 (*)
|    |    |    +--- com.google.api:gax-grpc:2.32.0
|    |    |    +--- com.google.api:gax-httpjson:2.32.0
|    |    |    |    +--- com.google.api:gax:2.32.0
|    |    |    +--- com.google.api:gax:2.32.0 (*)
|    |    |    +--- com.google.api:gax-grpc:2.32.0
|    |    |    +--- com.google.api:gax-httpjson:2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-httpjson:2.46.1 -> 2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-httpjson:2.46.1 -> 2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-httpjson:2.46.1 -> 2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-httpjson:2.46.1 -> 2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0
|    +--- com.google.api:gax-httpjson:2.46.1 -> 2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0 (c)
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0 (c)
|    +--- com.google.api:gax-httpjson:2.46.1 -> 2.32.0 (c)
     +--- com.google.api:gax:2.32.0
     +--- com.google.api:gax-grpc:2.32.0
     +--- com.google.api:gax-httpjson:2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0 (c)
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0 (c)
|    +--- com.google.api:gax-httpjson:2.46.1 -> 2.32.0 (c)
     +--- com.google.api:gax:2.32.0
     +--- com.google.api:gax-grpc:2.32.0
     +--- com.google.api:gax-httpjson:2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0 (c)
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0 (c)
|    +--- com.google.api:gax-httpjson:2.46.1 -> 2.32.0 (c)
     +--- com.google.api:gax:2.32.0
     +--- com.google.api:gax-grpc:2.32.0
     +--- com.google.api:gax-httpjson:2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0 (c)
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0 (c)
|    +--- com.google.api:gax-httpjson:2.46.1 -> 2.32.0 (c)
|    +--- com.google.api:gax:2.32.0
|    +--- com.google.api:gax-grpc:2.32.0
|    +--- com.google.api:gax-httpjson:2.32.0
|    +--- com.google.api:gax:2.46.1 -> 2.32.0 (c)
|    +--- com.google.api:gax-grpc:2.46.1 -> 2.32.0 (c)
|    +--- com.google.api:gax-httpjson:2.46.1 -> 2.32.0 (c)
|    +--- com.google.api:gax:2.32.0
|    +--- com.google.api:gax-grpc:2.32.0
|    +--- com.google.api:gax-httpjson:2.32.0
     |    |    |    +--- com.google.api:gax:2.32.0
     |    |    +--- com.google.api:gax-httpjson:2.32.0
     |    |    +--- com.google.api:gax:2.32.0 (*)
     |    |    +--- com.google.api:gax-grpc:2.32.0
     |    |    |    +--- com.google.api:gax:2.32.0
     |    |    +--- com.google.api:gax-httpjson:2.32.0
     |    |    +--- com.google.api:gax:2.32.0 (*)
     |    |    +--- com.google.api:gax-grpc:2.32.0
     |    |    |    +--- com.google.api:gax:2.32.0
     |    |    +--- com.google.api:gax-httpjson:2.32.0
     |    |    +--- com.google.api:gax:2.32.0 (*)
     |    |    +--- com.google.api:gax-grpc:2.32.0
|    |    |    |    +--- com.google.api:gax:2.32.0
|    |    |    +--- com.google.api:gax-httpjson:2.32.0
|    |    |    +--- com.google.api:gax:2.32.0 (*)
|    |    |    +--- com.google.api:gax-grpc:2.32.0
|    |    |    |    +--- com.google.api:gax:2.32.0
|    |    |    +--- com.google.api:gax-httpjson:2.32.0
|    |    |    +--- com.google.api:gax:2.32.0 (*)
|    |    |    +--- com.google.api:gax-grpc:2.32.0
suztomo commented 7 months ago

@Manuel-Sphe From reading com.google.api:gax:2.46.1 -> 2.32.0, your Gradle file has some configuration (such as force or enforcedPlatform) to set the GAX version to 2.32.0.

Manuel-Sphe commented 7 months ago

Thanks This was coming from


|         +--- com.google.cloud:spring-cloud-gcp-starter:4.7.2
|         |    +--- com.google.cloud:spring-cloud-gcp-core:4.7.2
|         |    |    +--- com.google.cloud:google-cloud-core:2.22.0
|         |    |    |    +--- com.google.guava:guava:32.1.2-jre
|         |    |    |    |    +--- com.google.guava:guava-parent:32.1.2-jre
|         |    |    |    |    |    +--- com.google.code.findbugs:jsr305:3.0.2 (c)
|         |    |    |    |    |    +--- org.checkerframework:checker-qual:3.33.0 (c)
|         |    |    |    |    |    +--- com.google.errorprone:error_prone_annotations:2.18.0 (c)
|         |    |    |    |    |    \--- com.google.j2objc:j2objc-annotations:2.8 (c)
|         |    |    |    |    +--- 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 -> 3.33.0
|         |    |    |    |    \--- com.google.errorprone:error_prone_annotations -> 2.18.0
|         |    |    |    +--- com.google.api:gax:2.32.0```
suztomo commented 7 months ago

@Manuel-Sphe Is everything clear now? If you still have a mystery that needs to be solved, would you create a GitHub repository for a very simple Gradle project that reproduces the problem?

Manuel-Sphe commented 7 months ago

Yeah, everything is clear . Thanks a lot . Will do next time

dhananjay-mehta commented 3 months ago

Using the google-cloud-vertexai imported with maven com.google.cloud libraries-bom 26.34.0

If your project correctly uses the Libraries BOM 26.34.0 (see instruction), then your dependency tree should show gax 2.45.0 already.

Upgrading gax to version 2.45.0 from 2.38.0 helped, I was facing similar problem when using AiPlatform Library