Artifact Repository
When developing applications in a larger project, you may find a need to share common libraries across multiple teams or applications. If this library is a public OSS library, it's usually hosted on Maven Central. For an internal library, though, you'll need to use a private repository. Typically, in an on-premise datacenter, these Java (Maven) artifacts may be stored in private repositories such as Sonatype Nexus, or JFrog Artifactory.
On Google Cloud, you can continue setup/configure/use these repositories. JFrog can also run Artifactory as a hosted service on Google Cloud!
In addition, Google Cloud also has a fully managed artifact repository service called Artifact Registry (beta).

Artifact Registry

Artifact Registry is a fully managed artifact repository service - you can use it to store container images, NPM packages, and Java artifacts, without having to setup any infrastructure and worry about availably or disk space.
See Artifact Registry documentation for more information.

Enable API

1
gcloud services enable artifactregistry.googleapis.com
Copied!

Maven Repository

Artifact Registry can host Maven repositories to host the Java artifacts. Artifacts are hosted within a region of your choice, and you can apply Identity Access Management to control who can access/update artifacts.
Artifact Registry is currently in beta, and the Maven Repository feature is in Alpha. You'll need to sign up for the Alpha program first.
Sign up for Artifact Registry Alpha feature to try the hands-on instructions.
Once you are confirmed to be enrolled in the alpha program, you can give it a try!

Create a Maven Repository

1
gcloud beta artifacts repositories create private-maven-repo \
2
--repository-format=maven \
3
--location=us-central1
Copied!

List Artifacts

1
gcloud beta artifacts packages list \
2
--repository=private-maven-repo \
3
--location=us-central1
Copied!
There should be no artifacts at the moment.

Deploy a Maven Artifact

You need to update the build configuration (e.g., pom.xml) in order to configure an artifact to Artifact Registry's Maven repository. You can find the full configuration needed through by running the utility command:

Generate a New Project

This example will use Maven. First, create a brand new Maven project:
1
mvn archetype:generate \
2
-DinteractiveMode=false \
3
-DgroupId=com.example \
4
-DartifactId=common-libs \
5
-DarchetypeGroupId=org.apache.maven.archetypes \
6
-DarchetypeArtifactId=maven-archetype-quickstart
7
8
cd common-libs/
Copied!

Configuration

Once you have a Java project you want to publish to Artifact Registry, then you can use gcloud CLI to print out the configuration for your build system (Maven or Gradle). You'll need to use the configuration to be able to publish artifacts to the repository, or consume artifacts from the repository.
Maven
Gradle
1
gcloud beta artifacts print-settings mvn \
2
--repository=private-maven-repo \
3
--location=us-central1
Copied!
Note that an Artifact Registry Wagon extension is needed to publish to Artifact Registry.
1
gcloud beta artifacts print-settings gradle \
2
--repository=private-maven-repo \
3
--location=us-central1
Copied!
Note that an Artifact Registry Gradle plugin is needed to publish to Artifact Registry.
Artifact Registry's plugins will automatically detect the current Application Default Credentials to authorize access.
This example uses Maven, so edit the pom.xml to add the additional settings:
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
6
...
7
8
<!-- Add Distributuion Management -->
9
<distributionManagement>
10
...
11
</distributionManagement>
12
13
<!-- Add Repository -->
14
<repositories>
15
...
16
</repositories>
17
18
<build>
19
<!-- Add the Wagon Extension -->
20
<extensions>
21
<extension>
22
<groupId>com.google.cloud.artifactregistry</groupId>
23
<artifactId>artifactregistry-maven-wagon</artifactId>
24
<version>2.1.0</version>
25
</extension>
26
</extensions>
27
28
<pluginManagement>
29
...
30
</pluginManagement>
31
</build>
32
</project>
Copied!

Build and Deploy

1
mvn clean package deploy
Copied!
Verify that the artifact is published!
1
gcloud alpha artifacts packages list \
2
--repository=private-maven-repo \
3
--location=us-central1
Copied!
In the Cloud Console, you can also browse to Artifact Registry > private-maven-repo.
And see manage the artifacts:
Last modified 1yr ago