From 802a3289daee94573754e441fed48e4e89277243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Zaj=C4=85czkowski?= <148013+szpak@users.noreply.github.com> Date: Fri, 1 Sep 2023 21:50:05 +0200 Subject: [PATCH] Revert "Gradle 6.2 as minimum (#251)" This reverts commit 535705a3771ae83f57ac7e354240442cd139636e. Workaround for "null" values in credentails. See: https://github.com/gradle-nexus/publish-plugin/issues/267 --- .github/workflows/java-versions.yml | 2 +- README.md | 2 +- build.gradle.kts | 6 +- .../publishplugin/FindStagingRepository.kt | 7 +- .../InitializeNexusStagingRepository.kt | 7 +- .../publishplugin/NexusPublishPlugin.kt | 75 +++++++------------ stutter.lockfile | 4 +- 7 files changed, 41 insertions(+), 62 deletions(-) diff --git a/.github/workflows/java-versions.yml b/.github/workflows/java-versions.yml index 91467e4f..98e4e0fc 100644 --- a/.github/workflows/java-versions.yml +++ b/.github/workflows/java-versions.yml @@ -29,7 +29,7 @@ jobs: - name: Reduce number of Gradle regressions builds run: | # Keep only the last Gradle version per Stutter matrix; for each line this transformation is done: - # java11=6.2.2,6.9.4,7.0.2,7.6.1,8.0.2,8.1.1,8.2-rc-1 + # java11=6.0.1,6.9.4,7.0.2,7.6.1,8.0.2,8.1.1,8.2-rc-1 # -> # java11=8.2-rc-1 # The trick is that \2 will greedily eat everything before the last comma. diff --git a/README.md b/README.md index 1e6cdbe4..c906e93b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This plugin is intended as a replacement of the [Gradle Nexus Staging Plugin](ht ### Applying the plugin -The plugin must be applied to the root project and requires Gradle 6.2 or later. It is important to +The plugin must be applied to the root project and requires Gradle 6.0 or later. It is important to set the group and the version to the root project, so the plugin can detect if it is a snapshot version or not in order to select the correct repository where artifacts will be published. diff --git a/build.gradle.kts b/build.gradle.kts index 65c405ff..33539420 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -110,7 +110,7 @@ stutter { languageVersion = JavaLanguageVersion.of(8) } gradleVersions { - compatibleRange("6.2") + compatibleRange("6.0") } } register("java11") { @@ -118,7 +118,7 @@ stutter { languageVersion = JavaLanguageVersion.of(11) } gradleVersions { - compatibleRange("6.2") + compatibleRange("6.0") } } register("java17") { @@ -165,7 +165,7 @@ sourceSets { } kotlin.target.compilations.configureEach { - // Supporting Gradle 6.2+ needs to use Kotlin 1.3. + // Supporting Gradle 6.0+ needs to use Kotlin 1.3. // See https://docs.gradle.org/current/userguide/compatibility.html // For future maintainer: Kotlin 1.9.0 dropped support for Kotlin 1.3, it'll only support 1.4+. // This means Gradle 7.0 will be the lowest supportable version for plugins. diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/FindStagingRepository.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/FindStagingRepository.kt index eb4bf763..a9a1fdc1 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/FindStagingRepository.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/FindStagingRepository.kt @@ -16,7 +16,7 @@ package io.github.gradlenexus.publishplugin -import io.github.gradlenexus.publishplugin.internal.StagingRepositoryDescriptorRegistryBuildService +import io.github.gradlenexus.publishplugin.internal.InvalidatingStagingRepositoryDescriptorRegistry import io.github.gradlenexus.publishplugin.internal.determineStagingProfileId import org.gradle.api.Incubating import org.gradle.api.provider.Property @@ -29,8 +29,7 @@ import org.gradle.api.tasks.TaskAction abstract class FindStagingRepository : AbstractNexusStagingRepositoryTask() { @get:Internal - // TODO use @ServiceReference instead of @Internal when minimum is Gradle 8.0. - abstract val registry: Property + abstract val registry: Property @get:Optional @get:Input @@ -59,6 +58,6 @@ abstract class FindStagingRepository : AbstractNexusStagingRepositoryTask() { val descriptor = client.findStagingRepository(stagingProfileId, Regex(descriptionRegex)) logger.lifecycle("Staging repository for {} at {}, stagingProfileId '{}', descriptionRegex '{}' is '{}'", repository.name, serverUrl, stagingProfileId, descriptionRegex, descriptor.stagingRepositoryId) stagingRepositoryId.set(descriptor.stagingRepositoryId) - registry.get().registry[repository.name] = descriptor + registry.get()[repository.name] = descriptor } } diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/InitializeNexusStagingRepository.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/InitializeNexusStagingRepository.kt index 9370e610..e7288281 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/InitializeNexusStagingRepository.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/InitializeNexusStagingRepository.kt @@ -16,7 +16,7 @@ package io.github.gradlenexus.publishplugin -import io.github.gradlenexus.publishplugin.internal.StagingRepositoryDescriptorRegistryBuildService +import io.github.gradlenexus.publishplugin.internal.InvalidatingStagingRepositoryDescriptorRegistry import io.github.gradlenexus.publishplugin.internal.determineStagingProfileId import okhttp3.HttpUrl import org.gradle.api.provider.Property @@ -28,8 +28,7 @@ import org.gradle.api.tasks.TaskAction abstract class InitializeNexusStagingRepository : AbstractNexusStagingRepositoryTask() { @get:Internal - // TODO use @ServiceReference instead of @Internal when minimum is Gradle 8.0. - abstract val registry: Property + abstract val registry: Property @get:Optional @get:Input @@ -45,6 +44,6 @@ abstract class InitializeNexusStagingRepository : AbstractNexusStagingRepository val descriptor = client.createStagingRepository(stagingProfileId, repositoryDescription.get()) val consumerUrl = HttpUrl.get(serverUrl)!!.newBuilder().addEncodedPathSegments("repositories/${descriptor.stagingRepositoryId}/content/").build() logger.lifecycle("Created staging repository '{}' at {}", descriptor.stagingRepositoryId, consumerUrl) - registry.get().registry[repository.name] = descriptor + registry.get()[repository.name] = descriptor } } diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt index ef962daf..313b4d26 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt @@ -17,6 +17,7 @@ package io.github.gradlenexus.publishplugin import io.github.gradlenexus.publishplugin.NexusRepository.PublicationType +import io.github.gradlenexus.publishplugin.internal.InvalidatingStagingRepositoryDescriptorRegistry import io.github.gradlenexus.publishplugin.internal.StagingRepositoryDescriptorRegistryBuildService import org.gradle.api.Action import org.gradle.api.Plugin @@ -53,8 +54,8 @@ class NexusPublishPlugin : Plugin { "Plugin must be applied to the root project but was applied to ${project.path}" } - require(GradleVersion.current() >= GradleVersion.version("6.2")) { - "io.github.gradle-nexus.publish-plugin requires Gradle version 6.2+" + require(GradleVersion.current() >= GradleVersion.version("6.0")) { + "The plugin requires Gradle version 6.0+" } val registry = createRegistry(project) @@ -77,18 +78,19 @@ class NexusPublishPlugin : Plugin { } } - private fun createRegistry(rootProject: Project): Provider = - rootProject.gradle.sharedServices.registerIfAbsent( - "stagingRepositoryUrlRegistry", - StagingRepositoryDescriptorRegistryBuildService::class, - Action { } - ) + private fun createRegistry(rootProject: Project): Provider { + if (GradleVersion.current() >= GradleVersion.version("6.1")) { + return rootProject.gradle.sharedServices.registerIfAbsent( + "stagingRepositoryUrlRegistry", + StagingRepositoryDescriptorRegistryBuildService::class, + Action { } + ).map { it.registry } + } + val registry = InvalidatingStagingRepositoryDescriptorRegistry() + return rootProject.provider { registry } + } - private fun configureNexusTasks( - rootProject: Project, - extension: NexusPublishExtension, - registryService: Provider - ) { + private fun configureNexusTasks(rootProject: Project, extension: NexusPublishExtension, registry: Provider) { rootProject.tasks.withType(AbstractNexusStagingRepositoryTask::class.java).configureEach { clientTimeout.convention(extension.clientTimeout) connectTimeout.convention(extension.connectTimeout) @@ -98,14 +100,13 @@ class NexusPublishPlugin : Plugin { } rootProject.tasks.withType(AbstractTransitionNexusStagingRepositoryTask::class.java).configureEach { transitionCheckOptions.convention(extension.transitionCheckOptions) - usesService(registryService) - stagingRepositoryId.convention(registryService.map { it.registry[repository.get().name].stagingRepositoryId }) + stagingRepositoryId.convention(registry.map { it[repository.get().name].stagingRepositoryId }) } extension.repositories.all { - username.convention(rootProject.providers.gradleProperty("${name}Username").forUseAtConfigurationTimeCompat()) - password.convention(rootProject.providers.gradleProperty("${name}Password").forUseAtConfigurationTimeCompat()) + username.convention(rootProject.provider { rootProject.findProperty("${name}Username") as? String }) + password.convention(rootProject.provider { rootProject.findProperty("${name}Password") as? String }) publicationType.convention(PublicationType.MAVEN) - configureRepositoryTasks(rootProject.tasks, extension, this, registryService) + configureRepositoryTasks(rootProject.tasks, extension, this, registry) } extension.repositories.whenObjectRemoved { rootProject.tasks.named("initialize${capitalizedName}StagingRepository").configure { @@ -135,7 +136,7 @@ class NexusPublishPlugin : Plugin { tasks: TaskContainer, extension: NexusPublishExtension, repo: NexusRepository, - registryService: Provider + registryProvider: Provider ) { @Suppress("UNUSED_VARIABLE") // Keep it consistent. val retrieveStagingProfileTask = tasks.register( @@ -153,8 +154,7 @@ class NexusPublishPlugin : Plugin { ) { group = PublishingPlugin.PUBLISH_TASK_GROUP description = "Initializes the staging repository in '${repo.name}' Nexus instance." - registry.set(registryService) - usesService(registryService) + registry.set(registryProvider) repository.convention(repo) packageGroup.convention(extension.packageGroup) } @@ -163,8 +163,7 @@ class NexusPublishPlugin : Plugin { ) { group = PublishingPlugin.PUBLISH_TASK_GROUP description = "Finds the staging repository for ${repo.name}" - registry.set(registryService) - usesService(registryService) + registry.set(registryProvider) repository.convention(repo) packageGroup.convention(extension.packageGroup) descriptionRegex.convention(extension.repositoryDescription.map { "\\b" + Regex.escape(it) + "(\\s|$)" }) @@ -204,11 +203,7 @@ class NexusPublishPlugin : Plugin { } } - private fun configurePublishingForAllProjects( - rootProject: Project, - extension: NexusPublishExtension, - registry: Provider - ) { + private fun configurePublishingForAllProjects(rootProject: Project, extension: NexusPublishExtension, registry: Provider) { rootProject.afterEvaluate { allprojects { val publishingProject = this @@ -247,7 +242,7 @@ class NexusPublishPlugin : Plugin { private fun addPublicationRepositories( project: Project, extension: NexusPublishExtension, - registry: Provider + registry: Provider ): Map = extension.repositories.associateWith { nexusRepo -> createArtifactRepository(nexusRepo.publicationType.get(), project, nexusRepo, extension, registry) } @@ -257,7 +252,7 @@ class NexusPublishPlugin : Plugin { project: Project, nexusRepo: NexusRepository, extension: NexusPublishExtension, - registry: Provider + registry: Provider ): ArtifactRepository = when (publicationType) { PublicationType.MAVEN -> project.theExtension().repositories.maven { configureArtifactRepo(nexusRepo, extension, registry, false) @@ -276,7 +271,7 @@ class NexusPublishPlugin : Plugin { private fun T.configureArtifactRepo( nexusRepo: NexusRepository, extension: NexusPublishExtension, - registry: Provider, + registry: Provider, provideFallback: Boolean ) where T : UrlArtifactRepository, T : ArtifactRepository, T : AuthenticationSupported { name = nexusRepo.name @@ -332,13 +327,13 @@ class NexusPublishPlugin : Plugin { private fun getRepoUrl( nexusRepo: NexusRepository, extension: NexusPublishExtension, - registry: Provider, + registry: Provider, provideFallback: Boolean, artifactRepo: ArtifactRepository ): Provider = extension.useStaging.flatMap { useStaging -> if (useStaging) { - registry.map { it.registry }.map { descriptorRegistry -> + registry.map { descriptorRegistry -> if (provideFallback) { descriptorRegistry.invalidateLater(nexusRepo.name, artifactRepo) descriptorRegistry.tryGet(nexusRepo.name)?.stagingRepositoryUrl ?: nexusRepo.nexusUrl.get() @@ -380,17 +375,3 @@ private inline fun Project.theExtension(): T = this.extensions.findByType(it) ?: error("The plugin cannot be applied without the publishing plugin") } - -private fun Provider.forUseAtConfigurationTimeCompat(): Provider = - if (GradleVersion.current() < GradleVersion.version("6.5")) { - // Gradle < 6.5 doesn't have this function. - this - } else if (GradleVersion.current() < GradleVersion.version("7.4")) { - // Gradle 6.5 - 7.3 requires this function to be called. - @Suppress("DEPRECATION") - this.forUseAtConfigurationTime() - } else { - // Gradle >= 7.4 deprecated this function in favor of not calling it (became no-op, and will eventually nag). - // https://docs.gradle.org/current/userguide/upgrading_version_7.html#for_use_at_configuration_time_deprecation - this - } diff --git a/stutter.lockfile b/stutter.lockfile index bff6f5cf..6f46d4df 100644 --- a/stutter.lockfile +++ b/stutter.lockfile @@ -1,4 +1,4 @@ # DO NOT MODIFY: Generated by Stutter plugin. -java11=6.2.2,6.9.4,7.0.2,7.6.2,8.0.2,8.2.1 +java11=6.0.1,6.9.4,7.0.2,7.6.2,8.0.2,8.2.1 java17=7.3.3,7.6.2,8.0.2,8.2.1 -java8=6.2.2,6.9.4,7.0.2,7.6.2,8.0.2,8.2.1 +java8=6.0.1,6.9.4,7.0.2,7.6.2,8.0.2,8.2.1