From 8ef790d4e61922684b0cff7f54d55d661a8e31ee Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sun, 14 Jan 2024 13:58:38 +1100 Subject: [PATCH 1/9] Drop kotlin-dsl plugin in favour of directly applying Kotlin plugin Kotlin 1.8.22 has been selected as it's the last version to support Kotlin API version 1.3 which this plugin uses to support Gradle versions as old as Gradle 6.2. --- build.gradle.kts | 2 +- .../DefaultNexusRepositoryContainer.kt | 6 +- .../publishplugin/NexusPublishExtension.kt | 6 +- .../publishplugin/NexusPublishPlugin.kt | 261 +++++++++--------- .../publishplugin/NexusRepository.kt | 6 +- 5 files changed, 137 insertions(+), 144 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 495d62e6..1f3974f9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinVersion plugins { - `kotlin-dsl` + kotlin("jvm") version "1.8.22" id("com.gradle.plugin-publish") version "1.2.1" id("com.diffplug.spotless") version "6.23.3" id("com.github.johnrengelman.shadow") version "8.1.1" diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/DefaultNexusRepositoryContainer.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/DefaultNexusRepositoryContainer.kt index 9e16d22e..4df50e29 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/DefaultNexusRepositoryContainer.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/DefaultNexusRepositoryContainer.kt @@ -34,9 +34,9 @@ internal open class DefaultNexusRepositoryContainer @Inject constructor( sonatype(Action {}) override fun sonatype(action: Action): NexusRepository = create("sonatype") { - nexusUrl.set(URI.create("https://oss.sonatype.org/service/local/")) - snapshotRepositoryUrl.set(URI.create("https://oss.sonatype.org/content/repositories/snapshots/")) - action.execute(this) + it.nexusUrl.set(URI.create("https://oss.sonatype.org/service/local/")) + it.snapshotRepositoryUrl.set(URI.create("https://oss.sonatype.org/content/repositories/snapshots/")) + action.execute(it) } override fun configure(configureClosure: Closure<*>): NamedDomainObjectContainer = diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishExtension.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishExtension.kt index 10a431e8..fcf5a351 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishExtension.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishExtension.kt @@ -20,8 +20,6 @@ import org.gradle.api.Action import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.Property import org.gradle.api.tasks.Nested -import org.gradle.kotlin.dsl.domainObjectContainer -import org.gradle.kotlin.dsl.newInstance import java.time.Duration abstract class NexusPublishExtension(objects: ObjectFactory) { @@ -48,8 +46,8 @@ abstract class NexusPublishExtension(objects: ObjectFactory) { } val repositories: NexusRepositoryContainer = objects.newInstance( - DefaultNexusRepositoryContainer::class, - objects.domainObjectContainer(NexusRepository::class) + DefaultNexusRepositoryContainer::class.java, + objects.domainObjectContainer(NexusRepository::class.java) ) fun repositories(action: Action) { diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt index 1512f9cc..c6d1e80b 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt @@ -18,7 +18,6 @@ package io.github.gradlenexus.publishplugin import io.github.gradlenexus.publishplugin.NexusRepository.PublicationType import io.github.gradlenexus.publishplugin.internal.StagingRepositoryDescriptorRegistryBuildService -import org.gradle.api.Action import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task @@ -28,15 +27,9 @@ import org.gradle.api.artifacts.repositories.UrlArtifactRepository import org.gradle.api.provider.Provider import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.plugins.PublishingPlugin +import org.gradle.api.reflect.TypeOf.typeOf import org.gradle.api.tasks.TaskContainer import org.gradle.api.tasks.TaskProvider -import org.gradle.kotlin.dsl.create -import org.gradle.kotlin.dsl.invoke -import org.gradle.kotlin.dsl.named -import org.gradle.kotlin.dsl.register -import org.gradle.kotlin.dsl.registerIfAbsent -import org.gradle.kotlin.dsl.typeOf -import org.gradle.kotlin.dsl.withType import org.gradle.util.GradleVersion import java.net.URI import java.time.Duration @@ -59,7 +52,7 @@ class NexusPublishPlugin : Plugin { } val registry = createRegistry(project) - val extension = project.extensions.create(NexusPublishExtension.NAME) + val extension = project.extensions.create(NexusPublishExtension.NAME, NexusPublishExtension::class.java) configureExtension(project, extension) configureNexusTasks(project, extension, registry) configurePublishingForAllProjects(project, extension, registry) @@ -81,9 +74,8 @@ class NexusPublishPlugin : Plugin { private fun createRegistry(rootProject: Project): Provider = rootProject.gradle.sharedServices.registerIfAbsent( "stagingRepositoryUrlRegistry", - StagingRepositoryDescriptorRegistryBuildService::class, - Action { } - ) + StagingRepositoryDescriptorRegistryBuildService::class.java + ) { } private fun configureNexusTasks( rootProject: Project, @@ -91,51 +83,51 @@ class NexusPublishPlugin : Plugin { registryService: Provider ) { rootProject.tasks.withType(AbstractNexusStagingRepositoryTask::class.java).configureEach { - clientTimeout.convention(extension.clientTimeout) - connectTimeout.convention(extension.connectTimeout) - repositoryDescription.convention(extension.repositoryDescription) - useStaging.convention(extension.useStaging) + it.clientTimeout.convention(extension.clientTimeout) + it.connectTimeout.convention(extension.connectTimeout) + it.repositoryDescription.convention(extension.repositoryDescription) + it.useStaging.convention(extension.useStaging) // repository.convention() is set in configureRepositoryTasks(). } rootProject.tasks.withType(AbstractTransitionNexusStagingRepositoryTask::class.java).configureEach { - transitionCheckOptions.convention(extension.transitionCheckOptions) - usesService(registryService) - stagingRepositoryId.convention(registryService.map { it.registry[repository.get().name].stagingRepositoryId }) + it.transitionCheckOptions.convention(extension.transitionCheckOptions) + it.usesService(registryService) + it.stagingRepositoryId.convention(registryService.map { service -> service.registry[it.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 }) - publicationType.convention(PublicationType.MAVEN) - configureRepositoryTasks(rootProject.tasks, extension, this, registryService) + it.username.convention(rootProject.provider { rootProject.findProperty("${it.name}Username") as? String }) + it.password.convention(rootProject.provider { rootProject.findProperty("${it.name}Password") as? String }) + it.publicationType.convention(PublicationType.MAVEN) + configureRepositoryTasks(rootProject.tasks, extension, it, registryService) } - extension.repositories.whenObjectRemoved { - rootProject.tasks.named("initialize${capitalizedName}StagingRepository").configure { - enabled = false + extension.repositories.whenObjectRemoved { repository -> + rootProject.tasks.named("initialize${repository.capitalizedName}StagingRepository").configure { + it.enabled = false } - rootProject.tasks.named("find${capitalizedName}StagingRepository").configure { - enabled = false + rootProject.tasks.named("find${repository.capitalizedName}StagingRepository").configure { + it.enabled = false } - rootProject.tasks.named("close${capitalizedName}StagingRepository").configure { - enabled = false + rootProject.tasks.named("close${repository.capitalizedName}StagingRepository").configure { + it.enabled = false } - rootProject.tasks.named("release${capitalizedName}StagingRepository").configure { - enabled = false + rootProject.tasks.named("release${repository.capitalizedName}StagingRepository").configure { + it.enabled = false } - rootProject.tasks.named("closeAndRelease${capitalizedName}StagingRepository").configure { - enabled = false + rootProject.tasks.named("closeAndRelease${repository.capitalizedName}StagingRepository").configure { + it.enabled = false } } rootProject.tasks.register(SIMPLIFIED_CLOSE_AND_RELEASE_TASK_NAME) { - group = PublishingPlugin.PUBLISH_TASK_GROUP - description = "Closes and releases open staging repositories in all configured Nexus instances." + it.group = PublishingPlugin.PUBLISH_TASK_GROUP + it.description = "Closes and releases open staging repositories in all configured Nexus instances." } rootProject.tasks.register(SIMPLIFIED_CLOSE_TASK_NAME) { - group = PublishingPlugin.PUBLISH_TASK_GROUP - description = "Closes open staging repositories in all configured Nexus instances." + it.group = PublishingPlugin.PUBLISH_TASK_GROUP + it.description = "Closes open staging repositories in all configured Nexus instances." } rootProject.tasks.register(SIMPLIFIED_RELEASE_TASK_NAME) { - group = PublishingPlugin.PUBLISH_TASK_GROUP - description = "Releases open staging repositories in all configured Nexus instances." + it.group = PublishingPlugin.PUBLISH_TASK_GROUP + it.description = "Releases open staging repositories in all configured Nexus instances." } } @@ -146,69 +138,74 @@ class NexusPublishPlugin : Plugin { registryService: Provider ) { @Suppress("UNUSED_VARIABLE") // Keep it consistent. - val retrieveStagingProfileTask = tasks.register( - "retrieve${repo.capitalizedName}StagingProfile" + val retrieveStagingProfileTask = tasks.register( + "retrieve${repo.capitalizedName}StagingProfile", + RetrieveStagingProfile::class.java ) { - group = PublishingPlugin.PUBLISH_TASK_GROUP - description = "Gets and displays a staging profile id for a given repository and package group. " + + it.group = PublishingPlugin.PUBLISH_TASK_GROUP + it.description = "Gets and displays a staging profile id for a given repository and package group. " + "This is a diagnostic task to get the value and " + "put it into the NexusRepository configuration closure as stagingProfileId." - repository.convention(repo) - packageGroup.convention(extension.packageGroup) + it.repository.convention(repo) + it.packageGroup.convention(extension.packageGroup) } - val initializeTask = tasks.register( - "initialize${repo.capitalizedName}StagingRepository" + val initializeTask = tasks.register( + "initialize${repo.capitalizedName}StagingRepository", + InitializeNexusStagingRepository::class.java ) { - group = PublishingPlugin.PUBLISH_TASK_GROUP - description = "Initializes the staging repository in '${repo.name}' Nexus instance." - registry.set(registryService) - usesService(registryService) - repository.convention(repo) - packageGroup.convention(extension.packageGroup) + it.group = PublishingPlugin.PUBLISH_TASK_GROUP + it.description = "Initializes the staging repository in '${repo.name}' Nexus instance." + it.registry.set(registryService) + it.usesService(registryService) + it.repository.convention(repo) + it.packageGroup.convention(extension.packageGroup) } - val findStagingRepository = tasks.register( - "find${repo.capitalizedName}StagingRepository" + val findStagingRepository = tasks.register( + "find${repo.capitalizedName}StagingRepository", + FindStagingRepository::class.java ) { - group = PublishingPlugin.PUBLISH_TASK_GROUP - description = "Finds the staging repository for ${repo.name}" - registry.set(registryService) - usesService(registryService) - repository.convention(repo) - packageGroup.convention(extension.packageGroup) - descriptionRegex.convention(extension.repositoryDescription.map { "\\b" + Regex.escape(it) + "(\\s|$)" }) + it.group = PublishingPlugin.PUBLISH_TASK_GROUP + it.description = "Finds the staging repository for ${repo.name}" + it.registry.set(registryService) + it.usesService(registryService) + it.repository.convention(repo) + it.packageGroup.convention(extension.packageGroup) + it.descriptionRegex.convention(extension.repositoryDescription.map { "\\b" + Regex.escape(it) + "(\\s|$)" }) } - val closeTask = tasks.register( - "close${repo.capitalizedName}StagingRepository" + val closeTask = tasks.register( + "close${repo.capitalizedName}StagingRepository", + CloseNexusStagingRepository::class.java ) { - group = PublishingPlugin.PUBLISH_TASK_GROUP - description = "Closes open staging repository in '${repo.name}' Nexus instance." - repository.convention(repo) + it.group = PublishingPlugin.PUBLISH_TASK_GROUP + it.description = "Closes open staging repository in '${repo.name}' Nexus instance." + it.repository.convention(repo) } - val releaseTask = tasks.register( - "release${repo.capitalizedName}StagingRepository" + val releaseTask = tasks.register( + "release${repo.capitalizedName}StagingRepository", + ReleaseNexusStagingRepository::class.java ) { - group = PublishingPlugin.PUBLISH_TASK_GROUP - description = "Releases closed staging repository in '${repo.name}' Nexus instance." - repository.convention(repo) + it.group = PublishingPlugin.PUBLISH_TASK_GROUP + it.description = "Releases closed staging repository in '${repo.name}' Nexus instance." + it.repository.convention(repo) } - val closeAndReleaseTask = tasks.register( + val closeAndReleaseTask = tasks.register( "closeAndRelease${repo.capitalizedName}StagingRepository" ) { - group = PublishingPlugin.PUBLISH_TASK_GROUP - description = "Closes and releases open staging repository in '${repo.name}' Nexus instance." + it.group = PublishingPlugin.PUBLISH_TASK_GROUP + it.description = "Closes and releases open staging repository in '${repo.name}' Nexus instance." } - closeTask { - mustRunAfter(initializeTask) - mustRunAfter(findStagingRepository) + closeTask.configure { + it.mustRunAfter(initializeTask) + it.mustRunAfter(findStagingRepository) } - releaseTask { - mustRunAfter(initializeTask) - mustRunAfter(findStagingRepository) - mustRunAfter(closeTask) + releaseTask.configure { + it.mustRunAfter(initializeTask) + it.mustRunAfter(findStagingRepository) + it.mustRunAfter(closeTask) } - closeAndReleaseTask { - dependsOn(closeTask, releaseTask) + closeAndReleaseTask.configure { + it.dependsOn(closeTask, releaseTask) } } @@ -218,9 +215,8 @@ class NexusPublishPlugin : Plugin { registry: Provider ) { rootProject.afterEvaluate { - allprojects { - val publishingProject = this - plugins.withType { + it.allprojects { publishingProject -> + publishingProject.plugins.withType(PublishingPlugin::class.java) { val nexusRepositories = addPublicationRepositories(publishingProject, extension, registry) nexusRepositories.forEach { (nexusRepo, publicationRepo) -> val publicationType = nexusRepo.publicationType.get() @@ -228,20 +224,20 @@ class NexusPublishPlugin : Plugin { PublicationType.IVY -> "ivy-publish" PublicationType.MAVEN -> "maven-publish" } - plugins.withId(id) { - val initializeTask = rootProject.tasks.named("initialize${nexusRepo.capitalizedName}StagingRepository") - val findStagingRepositoryTask = rootProject.tasks.named("find${nexusRepo.capitalizedName}StagingRepository") - val closeTask = rootProject.tasks.named("close${nexusRepo.capitalizedName}StagingRepository") - val releaseTask = rootProject.tasks.named("release${nexusRepo.capitalizedName}StagingRepository") + publishingProject.plugins.withId(id) { + val initializeTask = rootProject.tasks.named("initialize${nexusRepo.capitalizedName}StagingRepository", InitializeNexusStagingRepository::class.java) + val findStagingRepositoryTask = rootProject.tasks.named("find${nexusRepo.capitalizedName}StagingRepository", FindStagingRepository::class.java) + val closeTask = rootProject.tasks.named("close${nexusRepo.capitalizedName}StagingRepository", CloseNexusStagingRepository::class.java) + val releaseTask = rootProject.tasks.named("release${nexusRepo.capitalizedName}StagingRepository", ReleaseNexusStagingRepository::class.java) val publishAllTask = publishingProject.tasks.register("publishTo${nexusRepo.capitalizedName}") { - group = PublishingPlugin.PUBLISH_TASK_GROUP - description = "Publishes all Maven/Ivy publications produced by this project to the '${nexusRepo.name}' Nexus repository." + it.group = PublishingPlugin.PUBLISH_TASK_GROUP + it.description = "Publishes all Maven/Ivy publications produced by this project to the '${nexusRepo.name}' Nexus repository." } - closeTask { - mustRunAfter(publishAllTask) + closeTask.configure { task -> + task.mustRunAfter(publishAllTask) } - releaseTask { - mustRunAfter(publishAllTask) + releaseTask.configure { task -> + task.mustRunAfter(publishAllTask) } configureTaskDependencies(publishingProject, initializeTask, findStagingRepositoryTask, publishAllTask, closeTask, releaseTask, publicationRepo, publicationType) } @@ -268,15 +264,15 @@ class NexusPublishPlugin : Plugin { registry: Provider ): ArtifactRepository = when (publicationType) { PublicationType.MAVEN -> project.theExtension().repositories.maven { - configureArtifactRepo(nexusRepo, extension, registry, false) + it.configureArtifactRepo(nexusRepo, extension, registry, false) } - PublicationType.IVY -> project.theExtension().repositories.ivy { - configureArtifactRepo(nexusRepo, extension, registry, true) + PublicationType.IVY -> project.theExtension().repositories.ivy { repository -> + repository.configureArtifactRepo(nexusRepo, extension, registry, true) if (nexusRepo.ivyPatternLayout.isPresent) { - nexusRepo.ivyPatternLayout.get().let { this.patternLayout(it) } + nexusRepo.ivyPatternLayout.get().let { repository.patternLayout(it) } } else { - this.layout("maven") + repository.layout("maven") } } } @@ -294,8 +290,8 @@ class NexusPublishPlugin : Plugin { isAllowInsecureProtocol = allowInsecureProtocol } credentials { - username = nexusRepo.username.orNull - password = nexusRepo.password.orNull + it.username = nexusRepo.username.orNull + it.password = nexusRepo.password.orNull } } @@ -310,29 +306,28 @@ class NexusPublishPlugin : Plugin { publicationType: PublicationType ) { val publications = project.theExtension().publications.withType(publicationType.gradleType) - publications.configureEach { - val publication = this + publications.configureEach { publication -> val publishTask = project.tasks.named( "publish${publication.name.capitalize()}PublicationTo${artifactRepo.name.capitalize()}Repository", publicationType.publishTaskType ) - publishTask { - dependsOn(initializeTask) - mustRunAfter(findStagingRepositoryTask) - doFirst { + publishTask.configure { + it.dependsOn(initializeTask) + it.mustRunAfter(findStagingRepositoryTask) + it.doFirst { if (artifactRepo is UrlArtifactRepository) { - logger.info("Uploading to {}", artifactRepo.url) + it.logger.info("Uploading to {}", artifactRepo.url) } } } - publishAllTask { - dependsOn(publishTask) + publishAllTask.configure { + it.dependsOn(publishTask) } - closeTask { - mustRunAfter(publishTask) + closeTask.configure { + it.mustRunAfter(publishTask) } - releaseTask { - mustRunAfter(publishTask) + releaseTask.configure { + it.mustRunAfter(publishTask) } } } @@ -368,27 +363,27 @@ class NexusPublishPlugin : Plugin { "instance" } val closeAndReleaseSimplifiedTask = rootProject.tasks.named(SIMPLIFIED_CLOSE_AND_RELEASE_TASK_NAME) { - description = "Closes and releases open staging repositories in the following Nexus $instanceCardinalityAwareString: $repositoryNamesAsString" + it.description = "Closes and releases open staging repositories in the following Nexus $instanceCardinalityAwareString: $repositoryNamesAsString" } val closeSimplifiedTask = rootProject.tasks.named(SIMPLIFIED_CLOSE_TASK_NAME) { - description = "Closes open staging repositories in the following Nexus $instanceCardinalityAwareString: $repositoryNamesAsString" + it.description = "Closes open staging repositories in the following Nexus $instanceCardinalityAwareString: $repositoryNamesAsString" } val releaseSimplifiedTask = rootProject.tasks.named(SIMPLIFIED_RELEASE_TASK_NAME) { - description = "Releases open staging repositories in the following Nexus $instanceCardinalityAwareString: $repositoryNamesAsString" + it.description = "Releases open staging repositories in the following Nexus $instanceCardinalityAwareString: $repositoryNamesAsString" } extension.repositories.all { - val repositoryCapitalizedName = this.capitalizedName - val closeAndReleaseTask = rootProject.tasks.named("closeAndRelease${repositoryCapitalizedName}StagingRepository") - closeAndReleaseSimplifiedTask { - dependsOn(closeAndReleaseTask) + val repositoryCapitalizedName = it.capitalizedName + val closeAndReleaseTask = rootProject.tasks.named("closeAndRelease${repositoryCapitalizedName}StagingRepository") + closeAndReleaseSimplifiedTask.configure { + it.dependsOn(closeAndReleaseTask) } - val closeTask = rootProject.tasks.named("close${repositoryCapitalizedName}StagingRepository") - closeSimplifiedTask { - dependsOn(closeTask) + val closeTask = rootProject.tasks.named("close${repositoryCapitalizedName}StagingRepository") + closeSimplifiedTask.configure { + it.dependsOn(closeTask) } - val releaseTask = rootProject.tasks.named("release${repositoryCapitalizedName}StagingRepository") - releaseSimplifiedTask { - dependsOn(releaseTask) + val releaseTask = rootProject.tasks.named("release${repositoryCapitalizedName}StagingRepository") + releaseSimplifiedTask.configure { + it.dependsOn(releaseTask) } } } @@ -396,7 +391,7 @@ class NexusPublishPlugin : Plugin { } private inline fun Project.theExtension(): T = - typeOf().let { + typeOf(T::class.java).let { this.extensions.findByType(it) ?: error("The plugin cannot be applied without the publishing plugin") } diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusRepository.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusRepository.kt index f3a8c5b5..afdc9e3c 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusRepository.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusRepository.kt @@ -65,8 +65,8 @@ abstract class NexusRepository(@Input val name: String) { ivyPatternLayout.set(action) } - enum class PublicationType(internal val gradleType: KClass, internal val publishTaskType: KClass) { - MAVEN(MavenPublication::class, PublishToMavenRepository::class), - IVY(IvyPublication::class, PublishToIvyRepository::class) + enum class PublicationType(internal val gradleType: Class, internal val publishTaskType: Class) { + MAVEN(MavenPublication::class.java, PublishToMavenRepository::class.java), + IVY(IvyPublication::class.java, PublishToIvyRepository::class.java) } } From 5c2a96fa248bb2d0380c836a923efaf746512e58 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sun, 14 Jan 2024 13:59:03 +1100 Subject: [PATCH 2/9] Remove unused function --- .../publishplugin/NexusPublishPlugin.kt | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt index c6d1e80b..25fe2acf 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt @@ -395,17 +395,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 - } From 0610de8420a2b9e13e48c60d442917415a7cc37e Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sun, 14 Jan 2024 14:00:20 +1100 Subject: [PATCH 3/9] Fix warning --- .../io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt index 25fe2acf..a2104b93 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt @@ -223,6 +223,7 @@ class NexusPublishPlugin : Plugin { val id = when (publicationType) { PublicationType.IVY -> "ivy-publish" PublicationType.MAVEN -> "maven-publish" + null -> error("Repo publication type must be \"ivy-publish\" or \"maven-publish\"") } publishingProject.plugins.withId(id) { val initializeTask = rootProject.tasks.named("initialize${nexusRepo.capitalizedName}StagingRepository", InitializeNexusStagingRepository::class.java) From d0c41cef99e646ba064422633b82d365b6ec625f Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sun, 14 Jan 2024 14:01:49 +1100 Subject: [PATCH 4/9] Fix implict lambda parameter shadowing --- .../publishplugin/NexusPublishPlugin.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt index a2104b93..e03a73c8 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusPublishPlugin.kt @@ -170,7 +170,7 @@ class NexusPublishPlugin : Plugin { it.usesService(registryService) it.repository.convention(repo) it.packageGroup.convention(extension.packageGroup) - it.descriptionRegex.convention(extension.repositoryDescription.map { "\\b" + Regex.escape(it) + "(\\s|$)" }) + it.descriptionRegex.convention(extension.repositoryDescription.map { repoDescription -> "\\b" + Regex.escape(repoDescription) + "(\\s|$)" }) } val closeTask = tasks.register( "close${repo.capitalizedName}StagingRepository", @@ -230,9 +230,9 @@ class NexusPublishPlugin : Plugin { val findStagingRepositoryTask = rootProject.tasks.named("find${nexusRepo.capitalizedName}StagingRepository", FindStagingRepository::class.java) val closeTask = rootProject.tasks.named("close${nexusRepo.capitalizedName}StagingRepository", CloseNexusStagingRepository::class.java) val releaseTask = rootProject.tasks.named("release${nexusRepo.capitalizedName}StagingRepository", ReleaseNexusStagingRepository::class.java) - val publishAllTask = publishingProject.tasks.register("publishTo${nexusRepo.capitalizedName}") { - it.group = PublishingPlugin.PUBLISH_TASK_GROUP - it.description = "Publishes all Maven/Ivy publications produced by this project to the '${nexusRepo.name}' Nexus repository." + val publishAllTask = publishingProject.tasks.register("publishTo${nexusRepo.capitalizedName}") { task -> + task.group = PublishingPlugin.PUBLISH_TASK_GROUP + task.description = "Publishes all Maven/Ivy publications produced by this project to the '${nexusRepo.name}' Nexus repository." } closeTask.configure { task -> task.mustRunAfter(publishAllTask) @@ -315,9 +315,9 @@ class NexusPublishPlugin : Plugin { publishTask.configure { it.dependsOn(initializeTask) it.mustRunAfter(findStagingRepositoryTask) - it.doFirst { + it.doFirst { task -> if (artifactRepo is UrlArtifactRepository) { - it.logger.info("Uploading to {}", artifactRepo.url) + task.logger.info("Uploading to {}", artifactRepo.url) } } } @@ -375,16 +375,16 @@ class NexusPublishPlugin : Plugin { extension.repositories.all { val repositoryCapitalizedName = it.capitalizedName val closeAndReleaseTask = rootProject.tasks.named("closeAndRelease${repositoryCapitalizedName}StagingRepository") - closeAndReleaseSimplifiedTask.configure { - it.dependsOn(closeAndReleaseTask) + closeAndReleaseSimplifiedTask.configure { task -> + task.dependsOn(closeAndReleaseTask) } val closeTask = rootProject.tasks.named("close${repositoryCapitalizedName}StagingRepository") - closeSimplifiedTask.configure { - it.dependsOn(closeTask) + closeSimplifiedTask.configure { task -> + task.dependsOn(closeTask) } val releaseTask = rootProject.tasks.named("release${repositoryCapitalizedName}StagingRepository") - releaseSimplifiedTask.configure { - it.dependsOn(releaseTask) + releaseSimplifiedTask.configure { task -> + task.dependsOn(releaseTask) } } } From e4d7ee664f8113b34202011e8f7555394cab6592 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sun, 14 Jan 2024 14:18:36 +1100 Subject: [PATCH 5/9] Remove unused import --- .../io/github/gradlenexus/publishplugin/NexusRepository.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusRepository.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusRepository.kt index afdc9e3c..c826a729 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusRepository.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusRepository.kt @@ -29,7 +29,6 @@ import org.gradle.api.tasks.Input import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Optional import java.net.URI -import kotlin.reflect.KClass abstract class NexusRepository(@Input val name: String) { From ed7dd66305384545a6a5d74fae94c7a893c5cba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Papp=20=28TWiStErRob=29?= Date: Tue, 25 Jul 2023 17:50:23 +0100 Subject: [PATCH 6/9] Remove Kotlin 1.4 stdlib function. --- .../publishplugin/internal/StagingRepositoryTransitioner.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/io/github/gradlenexus/publishplugin/internal/StagingRepositoryTransitioner.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/internal/StagingRepositoryTransitioner.kt index 28af9f37..462a3530 100644 --- a/src/main/kotlin/io/github/gradlenexus/publishplugin/internal/StagingRepositoryTransitioner.kt +++ b/src/main/kotlin/io/github/gradlenexus/publishplugin/internal/StagingRepositoryTransitioner.kt @@ -59,7 +59,7 @@ class StagingRepositoryTransitioner(val nexusClient: NexusClient, val retrier: A private fun assertRepositoryInDesiredState(repository: StagingRepository, vararg desiredStates: StagingRepository.State) { if (repository.state !in desiredStates) { throw RepositoryTransitionException( - "Staging repository is not in desired state ${desiredStates.contentToString()}: $repository. It is unexpected. Please check " + + "Staging repository is not in desired state ${desiredStates.contentDeepToString()}: $repository. It is unexpected. Please check " + "the Nexus logs using its web interface - it can be caused by validation rules violation (e.g. publishing artifacts with the " + "same version again). If not, please report it to https://github.com/gradle-nexus/publish-plugin/issues/ with the '--info' logs." ) From 39fd2ef649e2c15620160e4a57238bce8b3e625a Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sun, 14 Jan 2024 14:34:52 +1100 Subject: [PATCH 7/9] Add gradle-api to test classpath --- build.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 1f3974f9..cb196fdb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -95,6 +95,8 @@ dependencies { // but we are running CI on Java 8 in .github/workflows/java-versions.yml. testImplementation("org.mockito:mockito-junit-jupiter:4.11.0") testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0") + + testImplementation(gradleApi()) } java { From ef8acfce800a83e57d960627b93df46e0731de17 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sun, 14 Jan 2024 14:35:02 +1100 Subject: [PATCH 8/9] Update tests to remove use of kotlin-dsl --- .../publishplugin/TaskOrchestrationTest.kt | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/test/kotlin/io/github/gradlenexus/publishplugin/TaskOrchestrationTest.kt b/src/test/kotlin/io/github/gradlenexus/publishplugin/TaskOrchestrationTest.kt index ecd63e89..5f436a18 100644 --- a/src/test/kotlin/io/github/gradlenexus/publishplugin/TaskOrchestrationTest.kt +++ b/src/test/kotlin/io/github/gradlenexus/publishplugin/TaskOrchestrationTest.kt @@ -21,10 +21,6 @@ import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.create -import org.gradle.kotlin.dsl.get import org.gradle.testfixtures.ProjectBuilder import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Disabled @@ -68,8 +64,8 @@ class TaskOrchestrationTest { internal fun `transitioning task should not run after non-related publish`(transitioningTaskName: String) { // given initSingleProjectWithDefaultConfiguration() - project.extensions.configure { - repositories.create("myNexus") + project.extensions.configure(NexusPublishExtension::class.java) { + it.repositories.create("myNexus") } // expect assertGivenTaskMustNotRunAfterAnother(transitioningTaskName, "publishToMyNexus") @@ -105,8 +101,8 @@ class TaskOrchestrationTest { ) internal fun `simplified task without repository name should be available but trigger nothing if no repositories are configured`(simplifiedTaskName: String) { initSingleProjectWithDefaultConfiguration() - project.extensions.configure { - repositories.clear() + project.extensions.configure(NexusPublishExtension::class.java) { + it.repositories.clear() } val simplifiedTasks = project.getTasksByName(simplifiedTaskName, true) @@ -124,8 +120,8 @@ class TaskOrchestrationTest { ) internal fun `simplified task without repository name should depend on all normal tasks (created one per defined repository)`(simplifiedTaskName: String, sonatypeTaskName: String, otherNexusTaskName: String) { initSingleProjectWithDefaultConfiguration() - project.extensions.configure { - repositories.create("otherNexus") + project.extensions.configure(NexusPublishExtension::class.java) { + it.repositories.create("otherNexus") } val simplifiedTasks = getJustOneTaskByNameOrFail(simplifiedTaskName) @@ -146,8 +142,8 @@ class TaskOrchestrationTest { ) internal fun `description of simplified task contains names of all defined Nexus instances`(simplifiedTaskName: String) { initSingleProjectWithDefaultConfiguration() - project.extensions.configure { - repositories.create("otherNexus") + project.extensions.configure(NexusPublishExtension::class.java) { + it.repositories.create("otherNexus") } val simplifiedTasks = getJustOneTaskByNameOrFail(simplifiedTaskName) @@ -158,15 +154,15 @@ class TaskOrchestrationTest { } private fun initSingleProjectWithDefaultConfiguration() { - project.apply(plugin = "java") - project.apply(plugin = "maven-publish") - project.apply() - project.extensions.configure { - repositories.sonatype() + project.pluginManager.apply("java") + project.pluginManager.apply("maven-publish") + project.pluginManager.apply(NexusPublishPlugin::class.java) + project.extensions.configure(NexusPublishExtension::class.java) { + it.repositories.sonatype() } - project.extensions.configure { - publications.create("mavenJava") { - from(project.components["java"]) + project.extensions.configure(PublishingExtension::class.java) { + it.publications.create("mavenJava", MavenPublication::class.java) { publication -> + publication.from(project.components.getByName("java")) } } } From 27deff84bbff9b919e7126b91b16c331fa6ad7e7 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sun, 14 Jan 2024 15:31:32 +1100 Subject: [PATCH 9/9] Use traditional notation to apply Kotlin JVM plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: RĂ³bert Papp --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index cb196fdb..c23cce09 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinVersion plugins { - kotlin("jvm") version "1.8.22" + id("org.jetbrains.kotlin.jvm") version "1.8.22" id("com.gradle.plugin-publish") version "1.2.1" id("com.diffplug.spotless") version "6.23.3" id("com.github.johnrengelman.shadow") version "8.1.1"