Skip to content

Commit 662df8d

Browse files
committed
Document dependencyResolutionManagement for Gradle package consumers
Declare GitHub Packages dependency repositories in settings scripts with dependencyResolutionManagement, and clarify that publishing credentials stay in the build script while consuming uses settings.
1 parent fd1cdbe commit 662df8d

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

content/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ category:
3737

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

40-
You can authenticate to {% data variables.product.prodname_registry %} 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 {% data variables.product.pat_v1 %}. You can also configure Gradle Groovy and Kotlin DSL to recognize a single package or multiple packages in a repository.
40+
You can authenticate to {% data variables.product.prodname_registry %} with Gradle using either Gradle Groovy or Kotlin DSL. To publish packages, edit your _build.gradle_ file (Gradle Groovy) or _build.gradle.kts_ file (Kotlin DSL) to include your {% data variables.product.pat_v1 %}. To use packages as dependencies, declare the repository and credentials in your _settings.gradle_ file (Gradle Groovy) or _settings.gradle.kts_ file (Kotlin DSL). You can also configure Gradle Groovy and Kotlin DSL to recognize a single package or multiple packages in a repository.
4141

4242
{% ifversion ghes %}
4343
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 {% data variables.product.prodname_ghe_server %} instance.
@@ -169,7 +169,7 @@ subprojects {
169169

170170
## Using a published package
171171

172-
To use a published package from {% data variables.product.prodname_registry %}, add the package as a dependency and add the repository to your project. For more information, see [Declaring dependencies](https://docs.gradle.org/current/userguide/declaring_dependencies.html) in the Gradle documentation.
172+
To use a published package from {% data variables.product.prodname_registry %}, add the package as a dependency and declare the repository in your project. Gradle recommends declaring repositories in your settings script with `dependencyResolutionManagement`. For more information, see [Declaring dependencies](https://docs.gradle.org/current/userguide/declaring_dependencies.html) and [Centralizing repository declarations](https://docs.gradle.org/current/userguide/centralizing_repositories.html) in the Gradle documentation.
173173

174174
{% data reusables.package_registry.authenticate-step %}
175175
1. Add the package dependencies to your _build.gradle_ file (Gradle Groovy) or _build.gradle.kts_ file (Kotlin DSL) file.
@@ -190,31 +190,35 @@ To use a published package from {% data variables.product.prodname_registry %},
190190
}
191191
```
192192

193-
1. Add the repository to your _build.gradle_ file (Gradle Groovy) or _build.gradle.kts_ file (Kotlin DSL) file.
193+
1. Add the repository to your _settings.gradle_ file (Gradle Groovy) or _settings.gradle.kts_ file (Kotlin DSL) using a `dependencyResolutionManagement` block.
194194

195195
Example using Gradle Groovy:
196196

197197
```shell
198-
repositories {
199-
maven {
200-
url = uri("https://{% ifversion fpt or ghec %}maven.pkg.github.com{% else %}REGISTRY_URL{% endif %}/OWNER/REPOSITORY")
201-
credentials {
202-
username = providers.gradleProperty("gpr.user").getOrNull() ?: System.getenv("USERNAME")
203-
password = providers.gradleProperty("gpr.key").getOrNull() ?: System.getenv("TOKEN")
198+
dependencyResolutionManagement {
199+
repositories {
200+
maven {
201+
url = uri("https://{% ifversion fpt or ghec %}maven.pkg.github.com{% else %}REGISTRY_URL{% endif %}/OWNER/REPOSITORY")
202+
credentials {
203+
username = providers.gradleProperty("gpr.user").getOrNull() ?: System.getenv("USERNAME")
204+
password = providers.gradleProperty("gpr.key").getOrNull() ?: System.getenv("TOKEN")
205+
}
204206
}
205-
}
207+
}
206208
}
207209
```
208210

209211
Example using Kotlin DSL:
210212

211213
```shell
212-
repositories {
213-
maven {
214-
url = uri("https://{% ifversion fpt or ghec %}maven.pkg.github.com{% else %}REGISTRY_URL{% endif %}/OWNER/REPOSITORY")
215-
credentials {
216-
username = providers.gradleProperty("gpr.user").getOrNull() ?: System.getenv("USERNAME")
217-
password = providers.gradleProperty("gpr.key").getOrNull() ?: System.getenv("TOKEN")
214+
dependencyResolutionManagement {
215+
repositories {
216+
maven {
217+
url = uri("https://{% ifversion fpt or ghec %}maven.pkg.github.com{% else %}REGISTRY_URL{% endif %}/OWNER/REPOSITORY")
218+
credentials {
219+
username = providers.gradleProperty("gpr.user").getOrNull() ?: System.getenv("USERNAME")
220+
password = providers.gradleProperty("gpr.key").getOrNull() ?: System.getenv("TOKEN")
221+
}
218222
}
219223
}
220224
}

0 commit comments

Comments
 (0)