Skip to content

Commit

Permalink
fix: prevent the closing of a staging repository already closed (#477)
Browse files Browse the repository at this point in the history
* fix: prevent the closing of a staging repository already closed

* style: reduce repetitions

* fix: use when on state enum

---------

Co-authored-by: Danilo Pianini <[email protected]>
  • Loading branch information
nicolasfara and DanySK authored Feb 5, 2023
1 parent d1fe58f commit 8c1311c
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.danilopianini.gradle.mavencentral

import io.github.gradlenexus.publishplugin.internal.StagingRepository
import org.danilopianini.gradle.mavencentral.ProjectExtensions.registerTaskIfNeeded
import org.gradle.api.DefaultTask
import org.gradle.api.Project
Expand Down Expand Up @@ -123,7 +124,15 @@ private fun Project.configureNexusRepository(repoToConfigure: Repository, nexusU
val closeStagingRepository = rootProject.registerTaskIfNeeded<DefaultTask>(
"closeStagingRepositoryOn${repoToConfigure.name}"
) {
doLast { nexusClient.nexusClient.close() }
doLast {
with(nexusClient.nexusClient) {
when (client.getStagingRepositoryStateById(repoId).state) {
StagingRepository.State.CLOSED ->
logger.warn("The staging repository is already closed. Skipping.")
else -> close()
}
}
}
dependsOn(createStagingRepository)
mustRunAfter(uploadAllPublications)
group = PublishingPlugin.PUBLISH_TASK_GROUP
Expand Down

0 comments on commit 8c1311c

Please sign in to comment.