Nota: Este tipo de paquete podría no estar disponible para tu instancia, ya que los administradores de sitio pueden habilitar o inhabilitar cada tipo de paquete compatible. Para obtener más información, consulta la sección "Configurar el soporte de los paquetes para tu empresa".
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 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 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". For more information about using GITHUB_TOKEN
with Gradle, see "Publishing Java packages with Gradle."
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 Gradle using either Gradle Groovy or Kotlin DSL by editing your build.gradle file (Gradle Groovy) or build.gradle.kts file (Kotlin DSL) file to include your personal access token. You can also configure Gradle Groovy and Kotlin DSL to recognize a single package or multiple packages in a repository.
Replace REGISTRY-URL with the URL for your instance's Maven registry. If your instance has subdomain isolation enabled, use maven.HOSTNAME
. If your instance has subdomain isolation disabled, use HOSTNAME/_registry/maven
. In either case, replace HOSTNAME with the host name of your GitHub Enterprise Server instance.
Replace USERNAME with your GitHub username, TOKEN with your personal access token, REPOSITORY with the name of the repository containing the package you want to publish, and OWNER with the name of the user or organization account on GitHub 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.
Note: 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. For an example, see "Configuring Apache Maven for use with Registro del paquete de GitHub."
Example using Gradle Groovy for a single package in a repository
plugins {
id("maven-publish")
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://REGISTRY-URL/OWNER/REPOSITORY")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("TOKEN")
}
}
}
publications {
gpr(MavenPublication) {
from(components.java)
}
}
}
Example using Gradle Groovy for multiple packages in the same repository
plugins {
id("maven-publish") apply false
}
subprojects {
apply plugin: "maven-publish"
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://REGISTRY-URL/OWNER/REPOSITORY")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("TOKEN")
}
}
}
publications {
gpr(MavenPublication) {
from(components.java)
}
}
}
}
Example using Kotlin DSL for a single package in the same repository
plugins {
`maven-publish`
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://REGISTRY-URL/OWNER/REPOSITORY")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
}
}
}
publications {
register<MavenPublication>("gpr") {
from(components["java"])
}
}
}
Example using Kotlin DSL for multiple packages in the same repository
plugins {
`maven-publish` apply false
}
subprojects {
apply(plugin = "maven-publish")
configure<PublishingExtension> {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://REGISTRY-URL/OWNER/REPOSITORY")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
}
}
}
publications {
register<MavenPublication>("gpr") {
from(components["java"])
}
}
}
}
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 the OWNER/test
Registro del paquete de GitHub repository.
Después de que publiques un paquete, puedes verlo en GitHub. Para obtener más información, consulta "Visualizar paquetes".
-
Autentícate en Registro del paquete de GitHub. Para obtener más información, consulta "Autenticar a Registro del paquete de GitHub."
-
After creating your package, you can publish the package.
$ gradle publish
Using a published package
To use a published package from Registro del paquete de GitHub, add the package as a dependency and add the repository to your project. For more information, see "Declaring dependencies" in the Gradle documentation.
-
Autentícate en Registro del paquete de GitHub. Para obtener más información, consulta "Autenticar a Registro del paquete de GitHub."
-
Add the package dependencies to your build.gradle file (Gradle Groovy) or build.gradle.kts file (Kotlin DSL) file.
Example using Gradle Groovy:
dependencies { implementation 'com.example:package' }
Example using Kotlin DSL:
dependencies { implementation("com.example:package") }
-
Add the repository to your build.gradle file (Gradle Groovy) or build.gradle.kts file (Kotlin DSL) file.
Example using Gradle Groovy:
repositories { maven { url = uri("https://REGISTRY-URL/OWNER/REPOSITORY") credentials { username = project.findProperty("gpr.user") ?: System.getenv("USERNAME") password = project.findProperty("gpr.key") ?: System.getenv("TOKEN") } } }
Example using Kotlin DSL:
repositories { maven { url = uri("https://REGISTRY-URL/OWNER/REPOSITORY") credentials { username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME") password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN") } } }