Configuring Apache Maven for use with GitHub Package Registry

You can publish an Apache Maven package to GitHub Package Registry and use it as a dependency in a Java project.

GitHub Package Registry is currently available in limited public beta. You should avoid using GitHub Package Registry for high-value workflows and content during the beta period. For more information, see "About GitHub Package Registry."

In this article

Authenticating to GitHub Package Registry

You must use a personal access token with the read:packages and write:packages scopes to publish and delete public packages in the GitHub Package Registry with Apache Maven. Your personal access token must also have the repo scope when the repository is private. For more information, see "Creating a personal access token for the command line."

You can also use a GITHUB_TOKEN to push packages to the GitHub Package Registry in a GitHub Actions workflow. For more information, see "`GITHUB_TOKEN secret."

Configure Apache Maven to use your token when pushing new packages by editing your ~/.m2/settings.xml file, or creating one it if it doesn't exist. The file should look similar to the example below. Replace USERNAME with your GitHub username, TOKEN with your personal access token, and OWNER with the GitHub user or organization name that contains the repository you will be publishing the package to or installing packages from.

<settings xmlns=""


          <name>GitHub OWNER Apache Maven Packages</name>


Publishing a package

When you push, by default the package is created in a repository with the same name as your package name. For example, a package named com.example.test would be published to the OWNER/test GitHub Package Registry repository. A GitHub Package Registry release and associated Git tag will be automatically created for the version of the package, if it doesn't already exist.

If you would like to publish multiple packages to the same repository, you can include the URL to the GitHub Package Registry repository in the <scm> section of pom.xml. GitHub Package Registry will match the repository based on that field.

For more information on creating your package, see the documentation.

Since the repository name is part of the distributionManagement section, there are no additional steps to publish multiple packages to the same repository.

  1. Edit the pom.xml file located in your package directory. It should look similar to the example below. Replace OWNER in the <url> with the GitHub Package Registry user or organization name that contains the repository you will be publishing the package to or installing packages from. Replace REPOSITORY with the name of the repository:

         <name>GitHub OWNER Apache Maven Packages</name>
  2. After you've created your package and are ready to publish it to your GitHub Package Registry user or organization, run:

    $ mvn deploy
  3. You can access your packages from this URL by replacing OWNER with your GitHub user or organization name and REPOSITORY with your repository name:

Receiving package registry events

You can receive webhook events when a package is published or updated. For more information, see "RegistryPackageEvent" in the GitHub Developer documentation.

Installing a package

  1. Set up Apache Maven to authenticate to GitHub Package Registry by editing your ~/.m2/settings.xml. For more information, see "Authenticating to GitHub Package Registry".

  2. Add the package dependencies to your pom.xml. For example this dependencies node of a pom.xml uses the com.example.test package:

  3. Install the package.

    $ mvn install

For more information on using a pom.xml in your project, see "Introduction to the POM" in the Apache Maven documentation.

Deleting a package

To avoid breaking projects that may depend on your packages, GitHub Package Registry does not support package deletion or deleting a version of a package. Under special circumstances, such as for legal reasons or to conform with GDPR standards, you can request deleting a package through GitHub Support. Contact GitHub Support using our contact form and the subject line "GitHub Package Registry."

Ask a human

Can't find what you're looking for?

Contact us