Frecuentemente publicamos actualizaciones de nuestra documentación. Es posible que la traducción de esta página esté en curso. Para conocer la información más actual, visita la documentación en inglés. Si existe un problema con las traducciones en esta página, por favor infórmanos.
GitHub AE está actualmente en un lanzamiento limitado. Por favor, contacta a nuestro equipo de ventas para conocer más sobre esto.

Working with the Apache Maven registry

You can configure Apache Maven to publish packages to Registro del paquete de GitHub and to use packages stored on Registro del paquete de GitHub as dependencies in a Java project.

el Registro del paquete de GitHub se encuentra disponible con GitHub Free, GitHub Pro, GitHub Free para organizaciones, GitHub Team, Nube de GitHub Enterprise, GitHub Enterprise Server, y GitHub AE.

Nota: El Registro del paquete de GitHub se encuentra actualmente en beta para GitHub AE.

Authenticating to Registro del paquete de GitHub

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

You can use a personal access token (PAT) to authenticate to Registro del paquete de GitHub or the GitHub AE 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 Registro del paquete de GitHub 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 obtener más información sobre el GITHUB_TOKEN que se utiliza en los flujos de trabajo de GitHub Actions, consulta la sección "Autenticarse en un flujo de trabajo".

Authenticating with a personal access token

Debes utilizar un token de acceso personal con los alcances adecuados para publicar e instalar paquetes en Registro del paquete de GitHub. Para obtener más información, consulta "Acerca de Registro del paquete de GitHub".

You can authenticate to Registro del paquete de GitHub 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 tu empresa, 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.

Registro del paquete de GitHub es compatible con versiones SNAPSHOT de Apache Maven. Para utilizar el repositorio del Registro del paquete de GitHub para descargar artefactos de SNAPSHOT, habilita las SNAPSHOTS en el POM del proyecto consumidor en tu archivo ~/.m2/settings.xml.

<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>

Publishing a package

Predeterminadamente, GitHub publica el paquete en un repositorio existente con el mismo nombre que éste. 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 tu empresa, 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.

    <distributionManagement>
       <repository>
         <id>github</id>
         <name>GitHub OWNER Apache Maven Packages</name>
         <url>https://maven.HOSTNAME/OWNER/REPOSITORY</url>
       </repository>
    </distributionManagement>
    
  2. In the plugins element of the pom.xml file, add the checksum-maven-plugin plugin, and configure the plugin to send at least SHA-256 checksums.

    <plugins>
        <plugin>
            <groupId>net.nicoulaj.maven.plugins</groupId>
            <artifactId>checksum-maven-plugin</artifactId>
            <version>1.9</version>
            <executions>
                <execution>
                <goals>
                    <goal>artifacts</goal>
                </goals>
                </execution>
            </executions>
            <configuration>
            <algorithms>
                <algorithm>SHA-256</algorithm>
            </algorithms>
            </configuration>
        </plugin>
    </plugins>
    
  3. Publish the package.

    $ mvn deploy

Después de que publiques un paquete, puedes verlo en GitHub. Para obtener más información, consulta "Visualizar paquetes".

Installing a package

To install an Apache Maven package from Registro del paquete de GitHub, 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. Autentícate en Registro del paquete de GitHub. Para obtener más información, consulta "Autenticar a Registro del paquete de GitHub."

  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. In the plugins element of the pom.xml file, add the checksum-maven-plugin plugin, and configure the plugin to send at least SHA-256 checksums.

    <plugins>
        <plugin>
            <groupId>net.nicoulaj.maven.plugins</groupId>
            <artifactId>checksum-maven-plugin</artifactId>
            <version>1.9</version>
            <executions>
                <execution>
                <goals>
                    <goal>artifacts</goal>
                </goals>
                </execution>
            </executions>
            <configuration>
            <algorithms>
                <algorithm>SHA-256</algorithm>
            </algorithms>
            </configuration>
        </plugin>
    </plugins>
    
  4. Install the package.

    $ mvn install

Further reading

¿Te ayudó este documento?

Política de privacidad

¡Ayúdanos a hacer geniales estos documentos!

Todos los documentos de GitHub son de código abierto. ¿Notas algo que esté mal o que no sea claro? Emite una solicitud de cambios.

Haz una contribución

O, aprende cómo contribuir.