注: サイト管理者はそれぞれのサポートされているパッケージの種類を有効化あるいは無効化できるので、このパッケージの種類はインスタンスで利用できないかもしれません。 詳細については、「エンタープライズ向けのパッケージ サポートの構成」を参照してく� さい。
Authenticating to GitHub Packages
You need an access token to publish, install, and delete private, internal, and public packages.
You can use a personal access token to authenticate to GitHub Packages 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 personal access token, see "About permissions for GitHub Packages."
To authenticate to a GitHub Packages registry within a GitHub Actions workflow, you can use:
GITHUB_TOKEN
to publish packages associated with the workflow repository.- a personal access token with at least
packages:read
scope to install packages associated with other private repositories (whichGITHUB_TOKEN
can't access).
GitHub Actions ワークフローで使用される GITHUB_TOKEN
の詳細については、「ワークフローで認証する」を参照してく� さい。 For more information about using GITHUB_TOKEN
with Gradle, see "Publishing Java packages with Gradle."
Authenticating with a personal access token
You must use a personal access token with the appropriate scopes to publish and install packages in GitHub Packages. For more information, see "About GitHub Packages."
You can authenticate to GitHub Packages 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: GitHub Packages では Apache Maven の SNAPSHOT
バージョンがサポートされています。 SNAPSHOT
成果物のダウンロードに GitHub Packages リポジトリを使用するには、それを使用するプロジェクトまたは ~/.m2/settings.xml ファイルの POM で SNAPSHOTS を有効にします。 For an example, see "Configuring Apache Maven for use with GitHub Packages."
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
デフォルトでは、GitHubはパッケージはそのままの名前で既存のリポジトリに公開されます。 For example, GitHub will publish a package named com.example.test
in the OWNER/test
GitHub Packages repository.
パッケージを公開した後は、GitHub上でそのパッケージを見ることができます。 詳しくは、「パッケージの表示」をご覧く� さい。
-
GitHub Packagesに認証を受けてく� さい。 詳細については、「GitHub Packages への認証」を参照してく� さい。
-
After creating your package, you can publish the package.
$ gradle publish
Using a published package
To use a published package from GitHub Packages, add the package as a dependency and add the repository to your project. For more information, see "Declaring dependencies" in the Gradle documentation.
-
GitHub Packagesに認証を受けてく� さい。 詳細については、「GitHub Packages への認証」を参照してく� さい。
-
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") } } }