google-auth-library-java: java.lang.ClassNotFoundException: com.google.auth.CredentialTypeForMetrics | v1.28.0

Environment details

  1. Specify the API at the beginning of the title. For example, “BigQuery: …”). General, Core, and Other are also allowed as types
  2. OS type and version: MacOS Sequoia 15.0
  3. Java version: 21
  4. version(s): 1.28.0

Steps to reproduce

  1. Use the version 1.28.0 in your pom
  2. Try to connect to a service (Google Drive in my case) and execute a query

Code example

            val query = "mimeType = 'application/vnd.google-apps.folder'"
            val result: FileList = when (nextPageToken) {
                null -> buildSharedDrive()
                    .setQ(query)
                    .setFields("nextPageToken, files(id, name)")
                    .execute()

Stack trace

Caused by: java.io.IOException: Unexpected error refreshing access token
	at com.google.auth.oauth2.OAuth2Credentials.unwrapDirectFuture(OAuth2Credentials.java:325)
	at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:183)
	at com.google.auth.oauth2.ServiceAccountCredentials.getRequestMetadataForGdu(ServiceAccountCredentials.java:1038)
	at com.google.auth.oauth2.ServiceAccountCredentials.getRequestMetadata(ServiceAccountCredentials.java:1016)
	at com.google.auth.http.HttpCredentialsAdapter.initialize(HttpCredentialsAdapter.java:96)
	at com.google.api.client.http.HttpRequestFactory.buildRequest(HttpRequestFactory.java:91)
	at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.buildHttpRequest(AbstractGoogleClientRequest.java:455)
	at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:565)
	at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:506)
	at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:616)
        at ...
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:348)
	at ...
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146)
	... 78 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/google/auth/CredentialTypeForMetrics
	at com.google.auth.oauth2.ServiceAccountCredentials.getMetricsCredentialType(ServiceAccountCredentials.java:1024)
	at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:512)
	at com.google.auth.oauth2.OAuth2Credentials$1.call(OAuth2Credentials.java:270)
	at com.google.auth.oauth2.OAuth2Credentials$1.call(OAuth2Credentials.java:267)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at com.google.auth.oauth2.OAuth2Credentials$RefreshTask.run(OAuth2Credentials.java:635)
	at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:31)
	at com.google.auth.oauth2.OAuth2Credentials$AsyncRefreshResult.executeIfNew(OAuth2Credentials.java:582)
	at com.google.auth.oauth2.OAuth2Credentials.asyncFetch(OAuth2Credentials.java:233)
	... 98 common frames omitted

Any additional information below

It’s a spring boot microservice using

        <dependency>
            <groupId>com.google.auth</groupId>
            <artifactId>google-auth-library-oauth2-http</artifactId>
            <version>1.28.0</version>
        </dependency>

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 17 (10 by maintainers)

Most upvoted comments

I was already using libraries-bom for the KMS dependency, as shown below. Initially, I thought that adding google-auth-library-oauth2-http would bring in all necessary dependencies automatically:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>libraries-bom</artifactId>
            <version>26.48.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-kms</artifactId>
</dependency>
<dependency>
    <groupId>com.google.auth</groupId>
    <artifactId>google-auth-library-oauth2-http</artifactId>
    <version>1.28.0</version>
</dependency>

The simple fix turned out to be explicitly adding google-auth-library-credentials:


<dependency>
    <groupId>com.google.auth</groupId>
    <artifactId>google-auth-library-credentials</artifactId>
    <version>1.28.0</version>
</dependency>

Thank you!

Could we see your Maven pom.xml or gradle file? I think it would be helpful if we could see the output of mvn dependency:tree or the gradle equivalent.

I believe the latest version of spring-cloud-gcp is pulling in libraries-bom v26.48.0 which pulls in Auth-Library v1.27.0.

Until a new version of spring-cloud-gcp is released with the updated libraries-bom (v26.49.0), you may need to explicitly pull in v1.28.0 of the auth-library-http and auth-library-credentials