javamavengoogle-secret-manager

Adding GCP Secret Manager SDK to Maven causes "{Type} Not Accessible" Error


Link to Code: https://github.com/phillipshaong/java-gcp-secrets-manager-test/tree/main

I want to add the Google Cloud Platform (GCP) Secrets Manager client to my Java application (https://cloud.google.com/secret-manager/docs/reference/libraries). I added dependencies to my pom.xml file as instructed:

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

<dependencies>
  <dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-secretmanager</artifactId>
  </dependency>

And added the module to my module-info.java file:

requires google.cloud.secretmanager;

When I import classes, as instructed:

import com.google.cloud.secretmanager.v1.AccessSecretVersionResponse;
import com.google.cloud.secretmanager.v1.ProjectName;
import com.google.cloud.secretmanager.v1.Replication;
import com.google.cloud.secretmanager.v1.Secret;
import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; //works
import com.google.cloud.secretmanager.v1.SecretPayload;
import com.google.cloud.secretmanager.v1.SecretVersion;
import com.google.protobuf.ByteString;

Only the import com.google.cloud.secretmanager.v1.SecretManagerServiceClient; imports successfully, all of the other classes do not, giving me error: The type com.google.cloud.secretmanager.v1.{Class} is not accessible).

Here is my minimally reproducible code. https://github.com/phillipshaong/java-gcp-secrets-manager-test/tree/main


Solution

  • Currently, the library google.cloud.secretmanager doesn't support importing though module-info.java. The Cloud Java SDK for Secret Manager doesn't work in a modularized project. The current known workaround is to repackage the JAR files. See thread: https://github.com/googleapis/google-cloud-java/issues/10975