17
17
package io.github.gradlenexus.publishplugin
18
18
19
19
import io.github.gradlenexus.publishplugin.NexusRepository.PublicationType
20
- import io.github.gradlenexus.publishplugin.internal.InvalidatingStagingRepositoryDescriptorRegistry
21
20
import io.github.gradlenexus.publishplugin.internal.StagingRepositoryDescriptorRegistryBuildService
22
21
import org.gradle.api.Action
23
22
import org.gradle.api.Plugin
@@ -54,8 +53,8 @@ class NexusPublishPlugin : Plugin<Project> {
54
53
" Plugin must be applied to the root project but was applied to ${project.path} "
55
54
}
56
55
57
- require(GradleVersion .current() >= GradleVersion .version(" 6.0 " )) {
58
- " The plugin requires Gradle version 6.0 +"
56
+ require(GradleVersion .current() >= GradleVersion .version(" 6.2 " )) {
57
+ " io.github.gradle-nexus.publish- plugin requires Gradle version 6.2 +"
59
58
}
60
59
61
60
val registry = createRegistry(project)
@@ -78,19 +77,18 @@ class NexusPublishPlugin : Plugin<Project> {
78
77
}
79
78
}
80
79
81
- private fun createRegistry (rootProject : Project ): Provider <InvalidatingStagingRepositoryDescriptorRegistry > {
82
- if (GradleVersion .current() >= GradleVersion .version(" 6.1" )) {
83
- return rootProject.gradle.sharedServices.registerIfAbsent(
84
- " stagingRepositoryUrlRegistry" ,
85
- StagingRepositoryDescriptorRegistryBuildService ::class ,
86
- Action { }
87
- ).map { it.registry }
88
- }
89
- val registry = InvalidatingStagingRepositoryDescriptorRegistry ()
90
- return rootProject.provider { registry }
91
- }
80
+ private fun createRegistry (rootProject : Project ): Provider <StagingRepositoryDescriptorRegistryBuildService > =
81
+ rootProject.gradle.sharedServices.registerIfAbsent(
82
+ " stagingRepositoryUrlRegistry" ,
83
+ StagingRepositoryDescriptorRegistryBuildService ::class ,
84
+ Action { }
85
+ )
92
86
93
- private fun configureNexusTasks (rootProject : Project , extension : NexusPublishExtension , registry : Provider <InvalidatingStagingRepositoryDescriptorRegistry >) {
87
+ private fun configureNexusTasks (
88
+ rootProject : Project ,
89
+ extension : NexusPublishExtension ,
90
+ registryService : Provider <StagingRepositoryDescriptorRegistryBuildService >
91
+ ) {
94
92
rootProject.tasks.withType(AbstractNexusStagingRepositoryTask ::class .java).configureEach {
95
93
clientTimeout.convention(extension.clientTimeout)
96
94
connectTimeout.convention(extension.connectTimeout)
@@ -100,13 +98,14 @@ class NexusPublishPlugin : Plugin<Project> {
100
98
}
101
99
rootProject.tasks.withType(AbstractTransitionNexusStagingRepositoryTask ::class .java).configureEach {
102
100
transitionCheckOptions.convention(extension.transitionCheckOptions)
103
- stagingRepositoryId.convention(registry.map { it[repository.get().name].stagingRepositoryId })
101
+ usesService(registryService)
102
+ stagingRepositoryId.convention(registryService.map { it.registry[repository.get().name].stagingRepositoryId })
104
103
}
105
104
extension.repositories.all {
106
- username.convention(rootProject.provider { rootProject.findProperty (" ${name} Username" ) as ? String } )
107
- password.convention(rootProject.provider { rootProject.findProperty (" ${name} Password" ) as ? String } )
105
+ username.convention(rootProject.providers.gradleProperty (" ${name} Username" ).forUseAtConfigurationTimeCompat() )
106
+ password.convention(rootProject.providers.gradleProperty (" ${name} Password" ).forUseAtConfigurationTimeCompat() )
108
107
publicationType.convention(PublicationType .MAVEN )
109
- configureRepositoryTasks(rootProject.tasks, extension, this , registry )
108
+ configureRepositoryTasks(rootProject.tasks, extension, this , registryService )
110
109
}
111
110
extension.repositories.whenObjectRemoved {
112
111
rootProject.tasks.named(" initialize${capitalizedName} StagingRepository" ).configure {
@@ -136,7 +135,7 @@ class NexusPublishPlugin : Plugin<Project> {
136
135
tasks : TaskContainer ,
137
136
extension : NexusPublishExtension ,
138
137
repo : NexusRepository ,
139
- registryProvider : Provider <InvalidatingStagingRepositoryDescriptorRegistry >
138
+ registryService : Provider <StagingRepositoryDescriptorRegistryBuildService >
140
139
) {
141
140
@Suppress(" UNUSED_VARIABLE" ) // Keep it consistent.
142
141
val retrieveStagingProfileTask = tasks.register<RetrieveStagingProfile >(
@@ -154,7 +153,8 @@ class NexusPublishPlugin : Plugin<Project> {
154
153
) {
155
154
group = PublishingPlugin .PUBLISH_TASK_GROUP
156
155
description = " Initializes the staging repository in '${repo.name} ' Nexus instance."
157
- registry.set(registryProvider)
156
+ registry.set(registryService)
157
+ usesService(registryService)
158
158
repository.convention(repo)
159
159
packageGroup.convention(extension.packageGroup)
160
160
}
@@ -163,7 +163,8 @@ class NexusPublishPlugin : Plugin<Project> {
163
163
) {
164
164
group = PublishingPlugin .PUBLISH_TASK_GROUP
165
165
description = " Finds the staging repository for ${repo.name} "
166
- registry.set(registryProvider)
166
+ registry.set(registryService)
167
+ usesService(registryService)
167
168
repository.convention(repo)
168
169
packageGroup.convention(extension.packageGroup)
169
170
descriptionRegex.convention(extension.repositoryDescription.map { " \\ b" + Regex .escape(it) + " (\\ s|$)" })
@@ -203,7 +204,11 @@ class NexusPublishPlugin : Plugin<Project> {
203
204
}
204
205
}
205
206
206
- private fun configurePublishingForAllProjects (rootProject : Project , extension : NexusPublishExtension , registry : Provider <InvalidatingStagingRepositoryDescriptorRegistry >) {
207
+ private fun configurePublishingForAllProjects (
208
+ rootProject : Project ,
209
+ extension : NexusPublishExtension ,
210
+ registry : Provider <StagingRepositoryDescriptorRegistryBuildService >
211
+ ) {
207
212
rootProject.afterEvaluate {
208
213
allprojects {
209
214
val publishingProject = this
@@ -242,7 +247,7 @@ class NexusPublishPlugin : Plugin<Project> {
242
247
private fun addPublicationRepositories (
243
248
project : Project ,
244
249
extension : NexusPublishExtension ,
245
- registry : Provider <InvalidatingStagingRepositoryDescriptorRegistry >
250
+ registry : Provider <StagingRepositoryDescriptorRegistryBuildService >
246
251
): Map <NexusRepository , ArtifactRepository > = extension.repositories.associateWith { nexusRepo ->
247
252
createArtifactRepository(nexusRepo.publicationType.get(), project, nexusRepo, extension, registry)
248
253
}
@@ -252,7 +257,7 @@ class NexusPublishPlugin : Plugin<Project> {
252
257
project : Project ,
253
258
nexusRepo : NexusRepository ,
254
259
extension : NexusPublishExtension ,
255
- registry : Provider <InvalidatingStagingRepositoryDescriptorRegistry >
260
+ registry : Provider <StagingRepositoryDescriptorRegistryBuildService >
256
261
): ArtifactRepository = when (publicationType) {
257
262
PublicationType .MAVEN -> project.theExtension<PublishingExtension >().repositories.maven {
258
263
configureArtifactRepo(nexusRepo, extension, registry, false )
@@ -271,7 +276,7 @@ class NexusPublishPlugin : Plugin<Project> {
271
276
private fun <T > T.configureArtifactRepo (
272
277
nexusRepo : NexusRepository ,
273
278
extension : NexusPublishExtension ,
274
- registry : Provider <InvalidatingStagingRepositoryDescriptorRegistry >,
279
+ registry : Provider <StagingRepositoryDescriptorRegistryBuildService >,
275
280
provideFallback : Boolean
276
281
) where T : UrlArtifactRepository, T : ArtifactRepository, T : AuthenticationSupported {
277
282
name = nexusRepo.name
@@ -327,13 +332,13 @@ class NexusPublishPlugin : Plugin<Project> {
327
332
private fun getRepoUrl (
328
333
nexusRepo : NexusRepository ,
329
334
extension : NexusPublishExtension ,
330
- registry : Provider <InvalidatingStagingRepositoryDescriptorRegistry >,
335
+ registry : Provider <StagingRepositoryDescriptorRegistryBuildService >,
331
336
provideFallback : Boolean ,
332
337
artifactRepo : ArtifactRepository
333
338
): Provider <URI > =
334
339
extension.useStaging.flatMap { useStaging ->
335
340
if (useStaging) {
336
- registry.map { descriptorRegistry ->
341
+ registry.map { it.registry }.map { descriptorRegistry ->
337
342
if (provideFallback) {
338
343
descriptorRegistry.invalidateLater(nexusRepo.name, artifactRepo)
339
344
descriptorRegistry.tryGet(nexusRepo.name)?.stagingRepositoryUrl ? : nexusRepo.nexusUrl.get()
@@ -375,3 +380,17 @@ private inline fun <reified T : Any> Project.theExtension(): T =
375
380
this .extensions.findByType(it)
376
381
? : error(" The plugin cannot be applied without the publishing plugin" )
377
382
}
383
+
384
+ private fun <T > Provider<T>.forUseAtConfigurationTimeCompat (): Provider <T > =
385
+ if (GradleVersion .current() < GradleVersion .version(" 6.5" )) {
386
+ // Gradle < 6.5 doesn't have this function.
387
+ this
388
+ } else if (GradleVersion .current() < GradleVersion .version(" 7.4" )) {
389
+ // Gradle 6.5 - 7.3 requires this function to be called.
390
+ @Suppress(" DEPRECATION" )
391
+ this .forUseAtConfigurationTime()
392
+ } else {
393
+ // Gradle >= 7.4 deprecated this function in favor of not calling it (became no-op, and will eventually nag).
394
+ // https://docs.gradle.org/current/userguide/upgrading_version_7.html#for_use_at_configuration_time_deprecation
395
+ this
396
+ }
0 commit comments