Store Java packages in Artifact Registry

This quickstart shows you how to set up a private Artifact Registry Mavenrepository and upload a package to it.


To follow step-by-step guidance for this task directly in the Google Cloud console, clickGuide me:

Guide me


Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  3. If you're using an existing project for this guide,verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Artifact Registry API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the API

  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  7. If you're using an existing project for this guide,verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  8. Verify that billing is enabled for your Google Cloud project.

  9. Enable the Artifact Registry API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the API

Required roles

To get the permissions that you need to create and manage Artifact Registry Java package repositories, ask your administrator to grant you theArtifact Registry Administrator (roles/artifactregistry.admin) IAM role on your project. For more information about granting roles, seeManage access to projects, folders, and organizations.

You might also be able to get the required permissions throughcustom roles or otherpredefined roles.

Launch Cloud Shell

In this quickstart, you will useCloud Shell,which is a shell environment for managing resources hosted onGoogle Cloud.

Cloud Shell comes preinstalled with theGoogle Cloud CLI and Java. The gcloud CLI provides the primary command-lineinterface for Google Cloud.

Launch Cloud Shell:

  1. Go to Google Cloud console.

    Google Cloud console

  2. On the Google Cloud console toolbar, clickActivate Cloud Shell:

A Cloud Shell session opens inside a frame lower on the console.You use this shell to rungcloud commands.

Create a Java package repository

Create the repository for your Java artifacts.

  1. Create the repository:

Console

  1. Open theRepositories page in the Google Cloud console.

    Open the Repositories page

  2. ClickCreate Repository.

  3. Specifyquickstart-java-repo as the repository name.

  4. ChooseMaven as the format andStandard as the mode.

  5. UnderLocation Type, selectRegion and then choose the locationus-central1.

  6. ClickCreate.

    The repository is added to the repository list.

gcloud

  1. Run the following command to create a new Java package repository in thecurrent project namedquickstart-java-repo in the locationus-central1.

    gcloudartifactsrepositoriescreatequickstart-java-repo--repository-format=maven\--location=us-central1--description="Java package repository"
  2. Run the following command to verify that your repository was created:

    gcloudartifactsrepositorieslist

    For more information about Artifact Registry commands, run thecommandgcloud artifacts.

Configure Maven

  1. Choose a simple Maven project that you want to use.

    If you don't have a simple project available, you can create theMaven in 5 minutes project.

    This quickstart assumes that your simple project does not have additionalparent or plugin dependencies stored in Artifact Registry. For detailsabout configuring a Maven project with dependencies inArtifact Registry, seeAuthenticating with a credential helper.

  2. To simplifygcloud commands, set the default repository toquickstart-java-repo and the default location tous-central1.After the values are set, you do not need to specify them ingcloudcommands that require a repository or a location.

    To set the repository, run the command:

    gcloudconfigsetartifacts/repositoryquickstart-java-repo

    To set the location, run the command:

    gcloudconfigsetartifacts/locationus-central1

    For more information about these commands, see thegcloud config set documentation.

  3. Run the following command to print the settings for the defaultquickstart-java-repo repository.

    gcloudartifactsprint-settingsmvn

    The output of thegcloud command looks like the following snippet,wherePROJECT is your project ID.

    <distributionManagement><snapshotRepository><id>artifact-registry</id><url>artifactregistry://us-central1-maven.pkg.dev/PROJECT/quickstart-java-repo</url></snapshotRepository><repository><id>artifact-registry</id><url>artifactregistry://us-central1-maven.pkg.dev/PROJECT/quickstart-java-repo</url></repository></distributionManagement><repositories><repository><id>artifact-registry</id><url>artifactregistry://us-central1-maven.pkg.dev/PROJECT/quickstart-java-repo</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories><build><extensions><extension><groupId>com.google.cloud.artifactregistry</groupId><artifactId>artifactregistry-maven-wagon</artifactId><version>2.2.5</version></extension></extensions></build>
  4. Add the settings to thepom.xml file for your Maven project. Thefollowing outline shows the relative placement of each main element.See the MavenPOM reference for details about the structure of the file.

    <projectxmlns="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.0http://maven.apache.org/xsd/maven-4.0.0.xsd"><!--BuildSettings--><build>...<extensions>...</extensions></build><!--EnvironmentSettings--><repositories>...</repositories><distributionManagement>...</distributionManagement></project>

Your Maven project can now upload packages to your repository.

Configure Gradle

Create a simple Gradle project to deploy a package to the Artifact Registryrepository you created. If you don't have a test Gradle build, you can followthe introductoryGradle tutorial to create a simple Gradle build.

To simplifygcloud commands, set the default repository toquickstart-java-repo and the default location tous-central1.After the values are set, you do not need to specify them ingcloudcommands that require a repository or a location.

To set the repository, run the command:

gcloudconfigsetartifacts/repositoryquickstart-java-repo

To set the location, run the command:

gcloudconfigsetartifacts/locationus-central1

For more information about these commands, see thegcloud config set documentation.

  1. Add settings to connect the repository to thebuild.gradle file. Thefollowing command prints settings to add for the defaultquickstart-java-reporepository.

    gcloudartifactsprint-settingsgradle

    The output of thegcloud command looks like the following example, wherePROJECT is your project ID.

    plugins{id"maven-publish"id"com.google.cloud.artifactregistry.gradle-plugin"version"2.2.5"}publishing{repositories{maven{url"artifactregistry://us-central1-maven.pkg.dev/PROJECT/quickstart-java-repo"}}}repositories{maven{url"artifactregistry://us-central1-maven.pkg.dev/PROJECT/quickstart-java-repo"}}
  2. Verify that thebuild.gradle file includes apublications section. If it does not, add it to yourbuild.gradle file.

    Thepublications section is a child ofpublishing as shownin the following example:

    publishing{publications{mavenJava(MavenPublication){groupId'maven.example.id'fromcomponents.java}}repositories{maven{url"artifactregistry://us-central1-maven.pkg.dev/PROJECT/quickstart-java-repo"}}}

    You can also add repository configuration to yourinit.gradle orsettings files. For details about these options, seeSetting up authentication.

    Upload a package to the repository

    For Maven, you can usemvn deploy andmvn release toadd packages to the repository.

    Note: Themvn archetype command is not supported if used exclusively from theArtifact Registry repository.

    For Gradle, use thegradle publish command to upload a package to therepository.

    View the package in the repository

    To verify that your package was added to the repository:

    Console

    1. Open theRepositories page in the Google Cloud console.

      Open the Repositories page

    2. In the repository list, click thequickstart-java-repo repository.

      ThePackages page lists the packages in the repository.

    gcloud

    1. To list the packages in thequickstart-java-repo repository, run the following command:

      gcloudartifactspackageslist--repository=quickstart-java-repo

      The output will be similar to the following:

      Listing items under project <project-id>, location us-central1,\repository quickstart-java-repo.PACKAGE: maven.example.id:gradle-demoCREATE_TIME: 2022-01-20T22:46:07UPDATE_TIME: 2022-01-20T22:46:07

      Wheremaven.example.id:gradle-demo is thepackage ID

      To view versions for a package, run the following command:

      gcloudartifactsversionslist--package=PACKAGE

      WherePACKAGE is the package ID.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

Before you remove the repository, ensure that any packages you want to keepare available in another location.

To delete the repository:

Console

  1. Open theRepositories page in the Google Cloud console.

    Open the Repositories page

  2. In the repository list, select thequickstart-java-repo repository.

  3. ClickDelete.

gcloud

  1. To delete thequickstart-java-repo repository, run the followingcommand:

    gcloudartifactsrepositoriesdeletequickstart-java-repo
  2. If you want to remove the default repository and location settings thatyou configured for the activegcloud configuration, run the followingcommands:

    gcloudconfigunsetartifacts/repositorygcloudconfigunsetartifacts/location

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.