Skip to main content
Publicamos atualizações frequentes em nossa documentação, e a tradução desta página ainda pode estar em andamento. Para obter as informações mais recentes, acesse a documentação em inglês. Se houver problemas com a tradução desta página, entre em contato conosco.

Esta versão do GitHub Enterprise foi descontinuada em 2022-06-03. Nenhum lançamento de patch será feito, mesmo para questões críticas de segurança. Para obter melhor desempenho, melhorar a segurança e novos recursos, upgrade to the latest version of GitHub Enterprise. Para ajuda com a atualização, contact GitHub Enterprise support.

Working with the Apache Maven registry

You can configure Apache Maven to publish packages to GitHub Package Registry and to use packages stored on GitHub Package Registry as dependencies in a Java project.

GitHub Package Registry is available with GitHub Free, GitHub Pro, GitHub Free for organizations, GitHub Team, GitHub Enterprise Cloud, GitHub Enterprise Server 3.0 or higher, and GitHub AE. For more information about upgrading your GitHub Enterprise Server instance, see "About upgrades to new releases" and refer to the Upgrade assistant to find the upgrade path from your current release version.

Nota: Este tipo de pacote pode não estar disponível para sua instância, porque os administradores do site podem habilitar ou desabilitar cada tipo de pacote compatível. Para obter mais informações, consulte "Configurar pacotes de suporte para a sua empresa".

Authenticating to GitHub Package Registry

You need an access token to publish, install, and delete packages.

You can use a personal access token (PAT) to authenticate to GitHub Package Registry or the GitHub Enterprise Server API. When you create a personal access token, you can assign the token different scopes depending on your needs. For more information about packages-related scopes for a PAT, see "About permissions for GitHub Packages."

To authenticate to a GitHub Package Registry registry within a GitHub Actions workflow, you can use:

  • GITHUB_TOKEN to publish packages associated with the workflow repository.
  • a PAT to install packages associated with other private repositories (which GITHUB_TOKEN can't access).

Para obter mais informações sobre GITHUB_TOKEN usado nos fluxos de trabalho de GitHub Actions, consulteAutenticação em um fluxo de trabalho".

Authenticating with a personal access token

Você deve usar um token de acesso pessoal com os escopos apropriados para publicar e instalar pacotes no GitHub Package Registry. Para obter mais informações, consulte "Sobre GitHub Package Registry."

You can authenticate to GitHub Package 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 GitHub 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 HOSTNAME with the host name of your GitHub Enterprise Server instance, and OWNER with the name of the user or organization account that owns the repository. Because uppercase letters aren't supported, you must use lowercase letters for the repository owner even if the GitHub user or organization name contains uppercase letters.

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.

GitHub Package Registry suporta versões SNAPSHOT do Apache Maven. Para usar o repositório GitHub Package Registry para fazer o download dos artefatos SNAPSHOT, habilite os INSTANTÂNEOS no POM do projeto que consome ou seu arquivo ~/. 2/settings.xml.

If your instance has subdomain isolation enabled:

<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>
        </repository>
        <repository>
          <id>github</id>
          <url>https://maven.HOSTNAME/OWNER/REPOSITORY</url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

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

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>
        </repository>
        <repository>
          <id>github</id>
          <url>HOSTNAME/_registry/maven/OWNER/REPOSITORY</url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

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

Publishing a package

Por padrão, o GitHub publica o pacote em um repositório existente com o mesmo nome do pacote. For example, GitHub 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. GitHub 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 HOSTNAME with the host name of your GitHub Enterprise Server instance, 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 your instance has subdomain isolation enabled:

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

    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>
    
  2. Publish the package.

    $ mvn deploy

Após publicar um pacote, você poderá visualizá-lo no GitHub. Para obter mais informações, consulte "Visualizar pacotes".

Installing a package

To install an Apache Maven package from GitHub Package 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.

  1. Autenticar para GitHub Package Registry. Para obter mais informações, consulte "Authenticating to GitHub Package Registry."

  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>
    
  3. Install the package.

    $ mvn install

Further reading