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

Gradle 6.2 as minimum #251

Merged
merged 6 commits into from
Jul 22, 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.0.1,6.9.4,7.0.2,7.6.1,8.0.2,8.1.1,8.2-rc-1
# java11=6.2.2,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.0 or later. It is important to
The plugin must be applied to the root project and requires Gradle 6.2 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 @@ -109,15 +109,15 @@ stutter {
languageVersion = JavaLanguageVersion.of(8)
}
gradleVersions {
compatibleRange("6.0")
compatibleRange("6.2")
}
}
register("java11") {
javaToolchain {
languageVersion = JavaLanguageVersion.of(11)
}
gradleVersions {
compatibleRange("6.0")
compatibleRange("6.2")
}
}
register("java17") {
Expand Down Expand Up @@ -164,7 +164,7 @@ sourceSets {
}

kotlin.target.compilations.configureEach {
// Supporting Gradle 6.0+ needs to use Kotlin 1.3.
// Supporting Gradle 6.2+ 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.InvalidatingStagingRepositoryDescriptorRegistry
import io.github.gradlenexus.publishplugin.internal.StagingRepositoryDescriptorRegistryBuildService
import io.github.gradlenexus.publishplugin.internal.determineStagingProfileId
import org.gradle.api.Incubating
import org.gradle.api.provider.Property
Expand All @@ -29,7 +29,8 @@ import org.gradle.api.tasks.TaskAction
abstract class FindStagingRepository : AbstractNexusStagingRepositoryTask() {

@get:Internal
abstract val registry: Property<InvalidatingStagingRepositoryDescriptorRegistry>
// TODO use @ServiceReference instead of @Internal when minimum is Gradle 8.0.
abstract val registry: Property<StagingRepositoryDescriptorRegistryBuildService>

@get:Optional
@get:Input
Expand Down Expand Up @@ -58,6 +59,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()[repository.name] = descriptor
registry.get().registry[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.InvalidatingStagingRepositoryDescriptorRegistry
import io.github.gradlenexus.publishplugin.internal.StagingRepositoryDescriptorRegistryBuildService
import io.github.gradlenexus.publishplugin.internal.determineStagingProfileId
import okhttp3.HttpUrl
import org.gradle.api.provider.Property
Expand All @@ -28,7 +28,8 @@ import org.gradle.api.tasks.TaskAction
abstract class InitializeNexusStagingRepository : AbstractNexusStagingRepositoryTask() {

@get:Internal
abstract val registry: Property<InvalidatingStagingRepositoryDescriptorRegistry>
// TODO use @ServiceReference instead of @Internal when minimum is Gradle 8.0.
abstract val registry: Property<StagingRepositoryDescriptorRegistryBuildService>

@get:Optional
@get:Input
Expand All @@ -44,6 +45,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()[repository.name] = descriptor
registry.get().registry[repository.name] = descriptor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
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 @@ -54,8 +53,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.0")) {
"The plugin requires Gradle version 6.0+"
require(GradleVersion.current() >= GradleVersion.version("6.2")) {
Copy link
Collaborator Author

@TWiStErRob TWiStErRob Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was rather writing about benefits of bumping required version to 6.2 :-)

If only we had some stats of Gradle version distributions out in the wild, like Android does: https://www.androidauthority.com/wp-content/uploads/2023/06/Android-version-distribution-statistics-May-2023-988w-675h.jpg.webp

It would be a much easier to say "minimum x".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked about that one friendly Gradle engineer ;-). We will see.

"io.github.gradle-nexus.publish-plugin requires Gradle version 6.2+"
}

val registry = createRegistry(project)
Expand All @@ -78,19 +77,18 @@ class NexusPublishPlugin : Plugin<Project> {
}
}

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 createRegistry(rootProject: Project): Provider<StagingRepositoryDescriptorRegistryBuildService> =
rootProject.gradle.sharedServices.registerIfAbsent(
"stagingRepositoryUrlRegistry",
StagingRepositoryDescriptorRegistryBuildService::class,
Action { }
)

private fun configureNexusTasks(rootProject: Project, extension: NexusPublishExtension, registry: Provider<InvalidatingStagingRepositoryDescriptorRegistry>) {
private fun configureNexusTasks(
rootProject: Project,
extension: NexusPublishExtension,
registryService: Provider<StagingRepositoryDescriptorRegistryBuildService>
) {
rootProject.tasks.withType(AbstractNexusStagingRepositoryTask::class.java).configureEach {
clientTimeout.convention(extension.clientTimeout)
connectTimeout.convention(extension.connectTimeout)
Expand All @@ -100,13 +98,14 @@ class NexusPublishPlugin : Plugin<Project> {
}
rootProject.tasks.withType(AbstractTransitionNexusStagingRepositoryTask::class.java).configureEach {
transitionCheckOptions.convention(extension.transitionCheckOptions)
stagingRepositoryId.convention(registry.map { it[repository.get().name].stagingRepositoryId })
usesService(registryService)
stagingRepositoryId.convention(registryService.map { it.registry[repository.get().name].stagingRepositoryId })
}
extension.repositories.all {
username.convention(rootProject.provider { rootProject.findProperty("${name}Username") as? String })
password.convention(rootProject.provider { rootProject.findProperty("${name}Password") as? String })
username.convention(rootProject.providers.gradleProperty("${name}Username").forUseAtConfigurationTimeCompat())
password.convention(rootProject.providers.gradleProperty("${name}Password").forUseAtConfigurationTimeCompat())
szpak marked this conversation as resolved.
Show resolved Hide resolved
publicationType.convention(PublicationType.MAVEN)
configureRepositoryTasks(rootProject.tasks, extension, this, registry)
configureRepositoryTasks(rootProject.tasks, extension, this, registryService)
}
extension.repositories.whenObjectRemoved {
rootProject.tasks.named("initialize${capitalizedName}StagingRepository").configure {
Expand Down Expand Up @@ -136,7 +135,7 @@ class NexusPublishPlugin : Plugin<Project> {
tasks: TaskContainer,
extension: NexusPublishExtension,
repo: NexusRepository,
registryProvider: Provider<InvalidatingStagingRepositoryDescriptorRegistry>
registryService: Provider<StagingRepositoryDescriptorRegistryBuildService>
) {
@Suppress("UNUSED_VARIABLE") // Keep it consistent.
val retrieveStagingProfileTask = tasks.register<RetrieveStagingProfile>(
Expand All @@ -154,7 +153,8 @@ class NexusPublishPlugin : Plugin<Project> {
) {
group = PublishingPlugin.PUBLISH_TASK_GROUP
description = "Initializes the staging repository in '${repo.name}' Nexus instance."
registry.set(registryProvider)
registry.set(registryService)
usesService(registryService)
repository.convention(repo)
packageGroup.convention(extension.packageGroup)
}
Expand All @@ -163,7 +163,8 @@ class NexusPublishPlugin : Plugin<Project> {
) {
group = PublishingPlugin.PUBLISH_TASK_GROUP
description = "Finds the staging repository for ${repo.name}"
registry.set(registryProvider)
registry.set(registryService)
usesService(registryService)
repository.convention(repo)
packageGroup.convention(extension.packageGroup)
descriptionRegex.convention(extension.repositoryDescription.map { "\\b" + Regex.escape(it) + "(\\s|$)" })
Expand Down Expand Up @@ -203,7 +204,11 @@ class NexusPublishPlugin : Plugin<Project> {
}
}

private fun configurePublishingForAllProjects(rootProject: Project, extension: NexusPublishExtension, registry: Provider<InvalidatingStagingRepositoryDescriptorRegistry>) {
private fun configurePublishingForAllProjects(
rootProject: Project,
extension: NexusPublishExtension,
registry: Provider<StagingRepositoryDescriptorRegistryBuildService>
) {
rootProject.afterEvaluate {
allprojects {
val publishingProject = this
Expand Down Expand Up @@ -242,7 +247,7 @@ class NexusPublishPlugin : Plugin<Project> {
private fun addPublicationRepositories(
project: Project,
extension: NexusPublishExtension,
registry: Provider<InvalidatingStagingRepositoryDescriptorRegistry>
registry: Provider<StagingRepositoryDescriptorRegistryBuildService>
): Map<NexusRepository, ArtifactRepository> = extension.repositories.associateWith { nexusRepo ->
createArtifactRepository(nexusRepo.publicationType.get(), project, nexusRepo, extension, registry)
}
Expand All @@ -252,7 +257,7 @@ class NexusPublishPlugin : Plugin<Project> {
project: Project,
nexusRepo: NexusRepository,
extension: NexusPublishExtension,
registry: Provider<InvalidatingStagingRepositoryDescriptorRegistry>
registry: Provider<StagingRepositoryDescriptorRegistryBuildService>
): ArtifactRepository = when (publicationType) {
PublicationType.MAVEN -> project.theExtension<PublishingExtension>().repositories.maven {
configureArtifactRepo(nexusRepo, extension, registry, false)
Expand All @@ -271,7 +276,7 @@ class NexusPublishPlugin : Plugin<Project> {
private fun <T> T.configureArtifactRepo(
nexusRepo: NexusRepository,
extension: NexusPublishExtension,
registry: Provider<InvalidatingStagingRepositoryDescriptorRegistry>,
registry: Provider<StagingRepositoryDescriptorRegistryBuildService>,
provideFallback: Boolean
) where T : UrlArtifactRepository, T : ArtifactRepository, T : AuthenticationSupported {
name = nexusRepo.name
Expand Down Expand Up @@ -327,13 +332,13 @@ class NexusPublishPlugin : Plugin<Project> {
private fun getRepoUrl(
nexusRepo: NexusRepository,
extension: NexusPublishExtension,
registry: Provider<InvalidatingStagingRepositoryDescriptorRegistry>,
registry: Provider<StagingRepositoryDescriptorRegistryBuildService>,
provideFallback: Boolean,
artifactRepo: ArtifactRepository
): Provider<URI> =
extension.useStaging.flatMap { useStaging ->
if (useStaging) {
registry.map { descriptorRegistry ->
registry.map { it.registry }.map { descriptorRegistry ->
if (provideFallback) {
descriptorRegistry.invalidateLater(nexusRepo.name, artifactRepo)
descriptorRegistry.tryGet(nexusRepo.name)?.stagingRepositoryUrl ?: nexusRepo.nexusUrl.get()
Expand Down Expand Up @@ -375,3 +380,17 @@ 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.0.1,6.9.4,7.0.2,7.6.2,8.0.2,8.2.1
java11=6.2.2,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.0.1,6.9.4,7.0.2,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
Loading