1
0
mirror of synced 2025-12-22 11:26:57 -05:00
Files
docs/content/packages/using-github-packages-with-your-projects-ecosystem/configuring-apache-maven-for-use-with-github-packages.md
Jason Etcovitch caaee7a124 Update all files to use {% data %} (#15253)
* Add back changes from prior to purge

* Manually fix some invalid Liquid

* Updoot render-content

* Improve test messages to show correct output

* Run el scripto

* Pass the remaining test
2020-09-29 16:01:04 -04:00

8.1 KiB

title, intro, product, redirect_from, versions
title intro product redirect_from versions
Configuring Apache Maven for use with GitHub Packages You can configure Apache Maven to publish packages to {% data variables.product.prodname_registry %} and to use packages stored on {% data variables.product.prodname_registry %} as dependencies in a Java project. {% data reusables.gated-features.packages %}
/articles/configuring-apache-maven-for-use-with-github-package-registry
/github/managing-packages-with-github-package-registry/configuring-apache-maven-for-use-with-github-package-registry
/github/managing-packages-with-github-packages/configuring-apache-maven-for-use-with-github-packages
free-pro-team enterprise-server
* >=2.22

{% data reusables.package_registry.packages-ghes-release-stage %}

{% data reusables.package_registry.admins-can-configure-package-types %}

Authenticating to {% data variables.product.prodname_registry %}

{% data reusables.package_registry.authenticate-packages %}

Authenticating with a personal access token

{% data reusables.package_registry.required-scopes %}

You can authenticate to {% data variables.product.prodname_registry %} with Apache Maven by editing your ~/.m2/settings.xml file to include your personal access token. Create a new ~/.m2/settings.xml file if one doesn't exist.

In the servers tag, add a child server tag with an id, replacing USERNAME with your {% data variables.product.prodname_dotcom %} username, and TOKEN with your personal access token.

In the repositories tag, configure a repository by mapping the id of the repository to the id you added in the server tag containing your credentials. Replace {% if currentVersion != "free-pro-team@latest" %}HOSTNAME with the host name of your {% data variables.product.prodname_ghe_server %} instance, {% endif %}REPOSITORY with the name of the repository you'd like to publish a package to or install a package from, and OWNER with the name of the user or organization account that owns the repository. {% data reusables.package_registry.lowercase-name-field %}

If you want to interact with multiple repositories, you can add each repository to separate repository children in the repositories tag, mapping the id of each to the credentials in the servers tag.

{% data reusables.package_registry.apache-maven-snapshot-versions-supported %}

{% if currentVersion != "free-pro-team@latest" %} If your instance has subdomain isolation enabled: {% endif %}

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <activeProfiles>
    <activeProfile>github</activeProfile>
  </activeProfiles>

  <profiles>
    <profile>
      <id>github</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
        <repository>
          <id>github</id>
          <name>GitHub OWNER Apache Maven Packages</name>
          <url>https://{% if currentVersion == "free-pro-team@latest" %}maven.pkg.github.com{% else %}maven.HOSTNAME{% endif %}/OWNER/REPOSITORY</url>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>github</id>
      <username>USERNAME</username>
      <password>TOKEN</password>
    </server>
  </servers>
</settings>

{% if currentVersion != "free-pro-team@latest" %} If your instance has subdomain isolation disabled:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <activeProfiles>
    <activeProfile>github</activeProfile>
  </activeProfiles>

  <profiles>
    <profile>
      <id>github</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
        <repository>
          <id>github</id>
          <name>GitHub OWNER Apache Maven Packages</name>
          <url>https://HOSTNAME/_registry/maven/OWNER/REPOSITORY</url>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>github</id>
      <username>USERNAME</username>
      <password>TOKEN</password>
    </server>
  </servers>
</settings>

{% endif %}

Authenticating with the GITHUB_TOKEN

{% data reusables.package_registry.package-registry-with-github-tokens %}

Publishing a package

{% data reusables.package_registry.default-name %} For example, {% data variables.product.prodname_dotcom %} will publish a package named com.example:test in a repository called OWNER/test.

If you would like to publish multiple packages to the same repository, you can include the URL of the repository in the <distributionManagement> element of the pom.xml file. {% data variables.product.prodname_dotcom %} will match the repository based on that field. Since the repository name is also part of the distributionManagement element, there are no additional steps to publish multiple packages to the same repository.

For more information on creating a package, see the maven.apache.org documentation.

  1. Edit the distributionManagement element of the pom.xml file located in your package directory, replacing {% if currentVersion != "free-pro-team@latest" %}HOSTNAME with the host name of your {% data variables.product.prodname_ghe_server %} instance, {% endif %}OWNER with the name of the user or organization account that owns the repository and REPOSITORY with the name of the repository containing your project. {% if currentVersion != "free-pro-team@latest" %} If your instance has subdomain isolation enabled: {% endif %}
<distributionManagement>
   <repository>
     <id>github</id>
     <name>GitHub OWNER Apache Maven Packages</name>
     <url>https://{% if currentVersion == "free-pro-team@latest" %}maven.pkg.github.com{% else %}maven.HOSTNAME{% endif %}/OWNER/REPOSITORY</url>
   </repository>
</distributionManagement>

{% if currentVersion != "free-pro-team@latest" %} If your instance has subdomain isolation disabled:

<distributionManagement>
   <repository>
     <id>github</id>
     <name>GitHub OWNER Apache Maven Packages</name>
     <url>https://HOSTNAME/_registry/maven/OWNER/REPOSITORY</url>
   </repository>
</distributionManagement>

{% endif %} 2. Publish the package.

$ mvn deploy

{% data reusables.package_registry.viewing-packages %}

Installing a package

To install an Apache Maven package from {% data variables.product.prodname_registry %}, edit the pom.xml file to include the package as a dependency. If you want to install packages from more than one repository, add a repository tag for each. For more information on using a pom.xml file in your project, see "Introduction to the POM" in the Apache Maven documentation.

{% data reusables.package_registry.authenticate-step %} 2. Add the package dependencies to the dependencies element of your project pom.xml file, replacing com.example:test with your package.

<dependencies>
  <dependency>
    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </dependency>
</dependencies>
  1. Install the package.
$ mvn install

Further reading