Working with Java packages

Artifact Registry supports Java packages that you build with Maven and Gradle.

Overview

To get familiar with Java packages in Artifact Registry, you can try the quickstart. You can also watch an overview video.

When you are ready to learn more, read the following information:

  1. Create a Java package repository for your packages.
  2. Grant permissions to the account that will connect with the repository. Service accounts for common integrations with Artifact Registry have default permissions for repositories in the same project.
  3. Configure your tools:
  4. Learn about managing packages.

Maven snapshot and release versions

Maven distinguishes between snapshot and release versions of your Maven projects.

Snapshots

A snapshot is a pre-release version of a Java project. The version number for a snapshot includes the suffix -SNAPSHOT in the your Project Object Model (POM). For example, this setting in the pom.xml file is for a 1.0 version of project that is in development:

<version>1.0-SNAPSHOT</version>

When you publish a package from this project, Maven 3 automatically appends a timestamp to the snapshot version number so that each snapshot version is unique. Maven 2 supports non-unique snapshot versions as a means to overwrite existing snapshots in a repository. This approach is problematic for reproducibility of builds, which is why Maven 3 no longer supports non-unique snapshots.

Snapshots provide a way for you to iteratively publish updated versions of a pre-release package without incrementing the version number in your Maven project every time that you publish to the repository. During development, other projects with dependencies on the package can then obtain the latest snapshot of version 1.0 from the repository.

Refer to version order specification for details about Maven version number syntax and sort order.

Releases

When you are ready to release a package, you remove the -SNAPSHOT suffix from the version number in the POM file and update any projects that depend on the package so that they use the release version instead of the snapshot version.

To list all snapshot dependencies, you can filter the dependency tree with the command:

mvn dependency:tree -Dincludes=:::*-SNAPSHOT

Artifact Registry version policy

When you create a Maven repository in Artifact Registry, you can specify a Maven version policy:

  • None - Stores both snapshot and release packages. This is the default setting.
  • Snapshot - Stores snapshot packages only.
  • Release - Stores release packages only.

If you choose the snapshot version policy, you can also specify whether the repository allows non-unique snapshot versions that overwrite matching versions in the repository. We recommend using unique versions since Maven 3 does not support the non-unique version model.

Video overview

This video provides an overview of Artifact Registry and how you can use Artifact Registry with Cloud Build to work with Java packages. For more information about using Cloud Build with Artifact Registry, see Integrating with Cloud Build