diff --git a/build.gradle.kts b/build.gradle.kts index 495d62e6..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-dsl` + 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" @@ -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 { 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..e03a73c8 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 { repoDescription -> "\\b" + Regex.escape(repoDescription) + "(\\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,30 +215,30 @@ 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() val id = when (publicationType) { PublicationType.IVY -> "ivy-publish" PublicationType.MAVEN -> "maven-publish" + null -> error("Repo publication type must be \"ivy-publish\" or \"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") - 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." + 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}") { 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 { - 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 +265,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 +291,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 +307,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 { task -> if (artifactRepo is UrlArtifactRepository) { - logger.info("Uploading to {}", artifactRepo.url) + task.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 +364,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 { task -> + task.dependsOn(closeAndReleaseTask) } - val closeTask = rootProject.tasks.named("close${repositoryCapitalizedName}StagingRepository") - closeSimplifiedTask { - dependsOn(closeTask) + val closeTask = rootProject.tasks.named("close${repositoryCapitalizedName}StagingRepository") + closeSimplifiedTask.configure { task -> + task.dependsOn(closeTask) } - val releaseTask = rootProject.tasks.named("release${repositoryCapitalizedName}StagingRepository") - releaseSimplifiedTask { - dependsOn(releaseTask) + val releaseTask = rootProject.tasks.named("release${repositoryCapitalizedName}StagingRepository") + releaseSimplifiedTask.configure { task -> + task.dependsOn(releaseTask) } } } @@ -396,21 +392,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") } - -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/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusRepository.kt b/src/main/kotlin/io/github/gradlenexus/publishplugin/NexusRepository.kt index f3a8c5b5..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) { @@ -65,8 +64,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) } } 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." ) 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")) } } }