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 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.
gcloud services enable artifactregistry.googleapis.com
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.
Once you are confirmed to be enrolled in the alpha program, you can give it a try!
gcloud beta artifacts repositories create private-maven-repo \--repository-format=maven \--location=us-central1
gcloud beta artifacts packages list \--repository=private-maven-repo \--location=us-central1
There should be no artifacts at the moment.
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:
This example will use Maven. First, create a brand new Maven project:
mvn archetype:generate \-DinteractiveMode=false \-DgroupId=com.example \-DartifactId=common-libs \-DarchetypeGroupId=org.apache.maven.archetypes \-DarchetypeArtifactId=maven-archetype-quickstartcd common-libs/
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.
gcloud beta artifacts print-settings mvn \--repository=private-maven-repo \--location=us-central1
Note that an Artifact Registry Wagon extension is needed to publish to Artifact Registry.
gcloud beta artifacts print-settings gradle \--repository=private-maven-repo \--location=us-central1
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:
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">...<!-- Add Distributuion Management --><distributionManagement>...</distributionManagement><!-- Add Repository --><repositories>...</repositories><build><!-- Add the Wagon Extension --><extensions><extension><groupId>com.google.cloud.artifactregistry</groupId><artifactId>artifactregistry-maven-wagon</artifactId><version>2.1.0</version></extension></extensions><pluginManagement>...</pluginManagement></build></project>
mvn clean package deploy
Verify that the artifact is published!
gcloud alpha artifacts packages list \--repository=private-maven-repo \--location=us-central1
In the Cloud Console, you can also browse to Artifact Registry > private-maven-repo.
And see manage the artifacts: