Features:
- Support for raw Google Cloud Storage buckets (
gs://) - Support Google Artifact Registry (
artifactregistry://) - Simple to use
- Coursier support (sbt 1.3+)
- Ability to configure Google Credentials using sbt settings
- sbt v2.1+
- sbt v1.x+
Releases after 2.1.0 support sbt 1.x and sbt 2.1 or later. sbt 2.0.x needs plugin version 2.1.0.
On sbt 2.1, publishing works for Maven resolvers ("name" at "gs://..." and "name" at "artifactregistry://...").
Ivy pattern resolvers (Resolver.url(...)(Resolver.ivyStylePatterns)) on these schemes are not supported for publishing there.
Add this to your project/plugins.sbt:
For sbt 1.x and sbt 2.1+:
addSbtPlugin("org.latestbit" % "sbt-gcs-plugin" % "2.2.0")For sbt 2.0.x:
addSbtPlugin("org.latestbit" % "sbt-gcs-plugin" % "2.1.0")publishTo := Some("My GCS artifacts" at "gs://<your-bucket-name>")resolvers += "My GCS artifacts" at "gs://<your-bucket-name>"publishTo := Some("My private artifacts" at "artifactregistry://<your-artifact-registry-url>")resolvers += "My private artifacts" at "artifactregistry://<your-artifact-registry-url>"Plugin tries to load Google Account in the following order:
- Specified settings in sbt build
Global / googleCredentialsFile := Some(new File("<your-account-file>"))
- Looking for
gcs-resolver-google-account.jsonin<user-home>/.sbtdirectory - Looking for the Access Token from the environment variable:
GOOGLE_OAUTH_ACCESS_TOKEN - Default application credentials (gcloud settings) or environment variable:
export GOOGLE_APPLICATION_CREDENTIALS=<your-account-file>If you see some errors such as The Application Default Credentials are not available.
when you start sbt, that means there is no default credentials configured on your machine.
You can use
gcloud auth application-default login to fix it or specify path to your account file
using environment variable GOOGLE_APPLICATION_CREDENTIALS.
Follow for details https://developers.google.com/accounts/docs/application-default-credentials.
The plugin supports Workload Identity Federation since it uses the official Google client for Java. The example how to use with GitHub Actions is:
- name: Authenticate Google Cloud
id: auth
uses: google-github-actions/auth@v1
with:
workload_identity_provider: 'projects/${{ env.GCP_PROJECT_ID }}/locations/global/workloadIdentityPools/${{ env.GCP_IDENTITY_POOL }}/providers/${{ env.GCP_IDENTITY_POOL_PROVIDER }}'
service_account: '${{ env.GCP_SA_NAME }}@${{ env.GCP_PROJECT }}.iam.gserviceaccount.com'
access_token_lifetime: '240s'
When the current credentials can no longer get an access token, the plugin loads them again using the same lookup order and retries once.
This happens when Google refuses to issue a token, e.g. for an expired or revoked refresh token, or when refreshing the token after a 401 response fails.
Network errors are reported as they are, without loading the credentials again.
So there is no need to restart sbt after:
gcloud auth application-default login, when your organization limits the lifetime of user credentials;- replacing the credentials file, for example a rotated service account key.
After changing googleCredentialsFile or googleCredentialsDisable in the build, you need to restart sbt, reload is not enough.
Be aware that GOOGLE_OAUTH_ACCESS_TOKEN is a static token and the plugin cannot refresh it.
When it expires, you need to export a new one and restart sbt.
Custom flows are configured with a credentials file, specified with googleCredentialsFile or GOOGLE_APPLICATION_CREDENTIALS.
The Google client for Java supports these file types:
external_accountfor Workload Identity Federation, including executable-sourced credentials (requiresGOOGLE_EXTERNAL_ACCOUNT_ALLOW_EXECUTABLES=1);impersonated_service_accountto act as a service account using your own credentials.
gcloud can generate them, e.g. gcloud iam workload-identity-pools create-cred-config or
gcloud auth application-default login --impersonate-service-account=<service-account-email>.
Full details available here: https://github.com/googleapis/google-auth-library-java
If you want to access publicly available buckets/registries without any authentication you can disable credentials loading using:
Global / googleCredentialsDisable := true
Global / gcsPublishFilePolicy := GcsPublishFilePolicy.InheritedFromBucket // Default
// If you really need to make some of the files available for everyone
Global / gcsPublishFilePolicy := GcsPublishFilePolicy.PublicAccess
For Google Artifact Registry please use Google Cloud IAM to manage security.
Apache Software License (ASL)
Abdulla Abdurakhmanov