How to download jar from artifact registry (GCP)?

Viewed 1351

I have a maven Artifact Registry and am able to add dependency in pom.xml and get the jar.

I have another usecase where I would like to only download the jar using CLI something which you can easily do with other external maven repos eg curl https://repo1.maven.org/maven2/org/apache/iceberg/iceberg-spark-runtime/0.7.0-incubating/iceberg-spark-runtime-0.7.0-incubating.jar --output temp.jar

I don't see any instructions about how to do this.

2 Answers

It seems like this feature as mentioned does not exist yet for Artifact Registry based on this open feature request (this feature request has currently no ETA). However, you can try to implement a Cloud build automation not to only save your built artifact in Artifact Registry, but also to store them in Google Cloud Storage or other Storage repositories; so you can easily access the JARs (since Cloud Storage supports direct downloading).

In order to do this, you would need to integrate Cloud Build with Artifact Registry. The documentation page has instructions to use Maven projects with Cloud Build and Artifact Registry. In addition, you can configure Cloud Build to store built artifacts in Cloud Storage.

Both of these integrations are configured through a Cloud Build configuration file. In this file, the steps for building a project are defined, including integrations to other serverless services. This integration would involve defining a target Maven repository:

steps:
- name: gcr.io/cloud-builders/mvn
  args: ['deploy']

And a location to deploy the artifacts into Cloud Storage:

artifacts:
  objects:
    location: [STORAGE_LOCATION]
    paths: [[ARTIFACT_PATH],[ARTIFACT_PATH], ...]

I needed this too. I have configured a service account following gcp guide

Then, I have executed the following command to get authbasic credz :

gcloud artifacts print-settings gradle \
    [--project=PROJECT] \
    [--repository=REPOSITORY] \
    [--location=LOCATION] \
    --json-key=KEY-FILE \
    [--version-policy=VERSION-POLICY] \
    [--allow-snapshot-overwrites]

In the output you have the artifactRegistryMavenSecret.

Finally you get your artifact with :

curl -L -u _json_key_base64:{{ artifactRegistryMavenSecret }} https://{{ region }}-maven.pkg.dev/{{ projectId }}/{{ repository }}/path/of/artifact/module/{{ version }}/app-{{ version }}.jar -o file.jar
Related