Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Gradle 6.2 as minimum (#251)" to fix regression with properties #268

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/java-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ stutter {
languageVersion = JavaLanguageVersion.of(8)
}
gradleVersions {
compatibleRange("6.2")
compatibleRange("6.0")
}
}
register("java11") {
javaToolchain {
languageVersion = JavaLanguageVersion.of(11)
}
gradleVersions {
compatibleRange("6.2")
compatibleRange("6.0")
}
}
register("java17") {
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<StagingRepositoryDescriptorRegistryBuildService>
abstract val registry: Property<InvalidatingStagingRepositoryDescriptorRegistry>

@get:Optional
@get:Input
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<StagingRepositoryDescriptorRegistryBuildService>
abstract val registry: Property<InvalidatingStagingRepositoryDescriptorRegistry>

@get:Optional
@get:Input
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,8 +54,8 @@ class NexusPublishPlugin : Plugin<Project> {
"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)
Expand All @@ -77,18 +78,19 @@ class NexusPublishPlugin : Plugin<Project> {
}
}

private fun createRegistry(rootProject: Project): Provider<StagingRepositoryDescriptorRegistryBuildService> =
rootProject.gradle.sharedServices.registerIfAbsent(
"stagingRepositoryUrlRegistry",
StagingRepositoryDescriptorRegistryBuildService::class,
Action { }
)
private fun createRegistry(rootProject: Project): Provider<InvalidatingStagingRepositoryDescriptorRegistry> {
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<StagingRepositoryDescriptorRegistryBuildService>
) {
private fun configureNexusTasks(rootProject: Project, extension: NexusPublishExtension, registry: Provider<InvalidatingStagingRepositoryDescriptorRegistry>) {
rootProject.tasks.withType(AbstractNexusStagingRepositoryTask::class.java).configureEach {
clientTimeout.convention(extension.clientTimeout)
connectTimeout.convention(extension.connectTimeout)
Expand All @@ -98,14 +100,13 @@ class NexusPublishPlugin : Plugin<Project> {
}
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 {
Expand Down Expand Up @@ -135,7 +136,7 @@ class NexusPublishPlugin : Plugin<Project> {
tasks: TaskContainer,
extension: NexusPublishExtension,
repo: NexusRepository,
registryService: Provider<StagingRepositoryDescriptorRegistryBuildService>
registryProvider: Provider<InvalidatingStagingRepositoryDescriptorRegistry>
) {
@Suppress("UNUSED_VARIABLE") // Keep it consistent.
val retrieveStagingProfileTask = tasks.register<RetrieveStagingProfile>(
Expand All @@ -153,8 +154,7 @@ class NexusPublishPlugin : Plugin<Project> {
) {
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)
}
Expand All @@ -163,8 +163,7 @@ class NexusPublishPlugin : Plugin<Project> {
) {
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|$)" })
Expand Down Expand Up @@ -204,11 +203,7 @@ class NexusPublishPlugin : Plugin<Project> {
}
}

private fun configurePublishingForAllProjects(
rootProject: Project,
extension: NexusPublishExtension,
registry: Provider<StagingRepositoryDescriptorRegistryBuildService>
) {
private fun configurePublishingForAllProjects(rootProject: Project, extension: NexusPublishExtension, registry: Provider<InvalidatingStagingRepositoryDescriptorRegistry>) {
rootProject.afterEvaluate {
allprojects {
val publishingProject = this
Expand Down Expand Up @@ -247,7 +242,7 @@ class NexusPublishPlugin : Plugin<Project> {
private fun addPublicationRepositories(
project: Project,
extension: NexusPublishExtension,
registry: Provider<StagingRepositoryDescriptorRegistryBuildService>
registry: Provider<InvalidatingStagingRepositoryDescriptorRegistry>
): Map<NexusRepository, ArtifactRepository> = extension.repositories.associateWith { nexusRepo ->
createArtifactRepository(nexusRepo.publicationType.get(), project, nexusRepo, extension, registry)
}
Expand All @@ -257,7 +252,7 @@ class NexusPublishPlugin : Plugin<Project> {
project: Project,
nexusRepo: NexusRepository,
extension: NexusPublishExtension,
registry: Provider<StagingRepositoryDescriptorRegistryBuildService>
registry: Provider<InvalidatingStagingRepositoryDescriptorRegistry>
): ArtifactRepository = when (publicationType) {
PublicationType.MAVEN -> project.theExtension<PublishingExtension>().repositories.maven {
configureArtifactRepo(nexusRepo, extension, registry, false)
Expand All @@ -276,7 +271,7 @@ class NexusPublishPlugin : Plugin<Project> {
private fun <T> T.configureArtifactRepo(
nexusRepo: NexusRepository,
extension: NexusPublishExtension,
registry: Provider<StagingRepositoryDescriptorRegistryBuildService>,
registry: Provider<InvalidatingStagingRepositoryDescriptorRegistry>,
provideFallback: Boolean
) where T : UrlArtifactRepository, T : ArtifactRepository, T : AuthenticationSupported {
name = nexusRepo.name
Expand Down Expand Up @@ -332,13 +327,13 @@ class NexusPublishPlugin : Plugin<Project> {
private fun getRepoUrl(
nexusRepo: NexusRepository,
extension: NexusPublishExtension,
registry: Provider<StagingRepositoryDescriptorRegistryBuildService>,
registry: Provider<InvalidatingStagingRepositoryDescriptorRegistry>,
provideFallback: Boolean,
artifactRepo: ArtifactRepository
): Provider<URI> =
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()
Expand Down Expand Up @@ -380,17 +375,3 @@ private inline fun <reified T : Any> Project.theExtension(): T =
this.extensions.findByType(it)
?: error("The plugin cannot be applied without the publishing plugin")
}

private fun <T> Provider<T>.forUseAtConfigurationTimeCompat(): Provider<T> =
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
}
4 changes: 2 additions & 2 deletions stutter.lockfile
Original file line number Diff line number Diff line change
@@ -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