Skip to content

Commit 6e2bc60

Browse files
subatoiCopilotCopilotShreckYe
authored
Use modern providers.gradleProperty APIs for GitHub Packages Gradle credential examples (#63710)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Yongshun Ye <shreckye@gmail.com>
1 parent 540fa38 commit 6e2bc60

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

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

Lines changed: 16 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 by editing your `build.gradle` file (Gradle Groovy) or `build.gradle.kts` file (Kotlin DSL) (`settings.gradle` or `settings.gradle.kts` if you centralize repository declarations in the settings script to use published packages) 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.
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.
@@ -60,8 +60,8 @@ publishing {
6060
name = "GitHubPackages"
6161
url = uri("https://{% ifversion fpt or ghec %}maven.pkg.github.com{% else %}REGISTRY_URL{% endif %}/OWNER/REPOSITORY")
6262
credentials {
63-
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
64-
password = project.findProperty("gpr.key") ?: System.getenv("TOKEN")
63+
username = providers.gradleProperty("gpr.user").getOrNull() ?: System.getenv("USERNAME")
64+
password = providers.gradleProperty("gpr.key").getOrNull() ?: System.getenv("TOKEN")
6565
}
6666
}
6767
}
@@ -87,8 +87,8 @@ subprojects {
8787
name = "GitHubPackages"
8888
url = uri("https://{% ifversion fpt or ghec %}maven.pkg.github.com{% else %}REGISTRY_URL{% endif %}/OWNER/REPOSITORY")
8989
credentials {
90-
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
91-
password = project.findProperty("gpr.key") ?: System.getenv("TOKEN")
90+
username = providers.gradleProperty("gpr.user").getOrNull() ?: System.getenv("USERNAME")
91+
password = providers.gradleProperty("gpr.key").getOrNull() ?: System.getenv("TOKEN")
9292
}
9393
}
9494
}
@@ -113,8 +113,8 @@ publishing {
113113
name = "GitHubPackages"
114114
url = uri("https://{% ifversion fpt or ghec %}maven.pkg.github.com{% else %}REGISTRY_URL{% endif %}/OWNER/REPOSITORY")
115115
credentials {
116-
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
117-
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
116+
username = providers.gradleProperty("gpr.user").getOrNull() ?: System.getenv("USERNAME")
117+
password = providers.gradleProperty("gpr.key").getOrNull() ?: System.getenv("TOKEN")
118118
}
119119
}
120120
}
@@ -140,8 +140,8 @@ subprojects {
140140
name = "GitHubPackages"
141141
url = uri("https://{% ifversion fpt or ghec %}maven.pkg.github.com{% else %}REGISTRY_URL{% endif %}/OWNER/REPOSITORY")
142142
credentials {
143-
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
144-
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
143+
username = providers.gradleProperty("gpr.user").getOrNull() ?: System.getenv("USERNAME")
144+
password = providers.gradleProperty("gpr.key").getOrNull() ?: System.getenv("TOKEN")
145145
}
146146
}
147147
}
@@ -172,7 +172,7 @@ subprojects {
172172
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.
173173

174174
{% data reusables.package_registry.authenticate-step %}
175-
1. Add the package dependencies to your _build.gradle_ file (Gradle Groovy) or _build.gradle.kts_ file (Kotlin DSL) file.
175+
1. Add the package dependencies to your `build.gradle` file (Gradle Groovy) or `build.gradle.kts` file (Kotlin DSL).
176176

177177
Example using Gradle Groovy:
178178

@@ -190,7 +190,7 @@ 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 `build.gradle` file (Gradle Groovy) or `build.gradle.kts` file (Kotlin DSL), or to your `settings.gradle` file (Gradle Groovy) or `settings.gradle.kts` file (Kotlin DSL) in the `dependencyResolutionManagement` block if you centralize repository declarations in the settings script. For more information, see [Centralizing Repository Declarations](https://docs.gradle.org/current/userguide/centralizing_repositories.html) in the Gradle documentation.
194194

195195
Example using Gradle Groovy:
196196

@@ -199,10 +199,10 @@ To use a published package from {% data variables.product.prodname_registry %},
199199
maven {
200200
url = uri("https://{% ifversion fpt or ghec %}maven.pkg.github.com{% else %}REGISTRY_URL{% endif %}/OWNER/REPOSITORY")
201201
credentials {
202-
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
203-
password = project.findProperty("gpr.key") ?: System.getenv("TOKEN")
202+
username = providers.gradleProperty("gpr.user").getOrNull() ?: System.getenv("USERNAME")
203+
password = providers.gradleProperty("gpr.key").getOrNull() ?: System.getenv("TOKEN")
204204
}
205-
}
205+
}
206206
}
207207
```
208208

@@ -213,8 +213,8 @@ To use a published package from {% data variables.product.prodname_registry %},
213213
maven {
214214
url = uri("https://{% ifversion fpt or ghec %}maven.pkg.github.com{% else %}REGISTRY_URL{% endif %}/OWNER/REPOSITORY")
215215
credentials {
216-
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
217-
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
216+
username = providers.gradleProperty("gpr.user").getOrNull() ?: System.getenv("USERNAME")
217+
password = providers.gradleProperty("gpr.key").getOrNull() ?: System.getenv("TOKEN")
218218
}
219219
}
220220
}

0 commit comments

Comments
 (0)