Codearte / gradle-nexus-staging-plugin

Automatize releasing Gradle projects to Maven Central.
Apache License 2.0
172 stars 26 forks source link

`closeRepository` task run before publishing all subprojects #157

Closed ihostage closed 3 years ago

ihostage commented 4 years ago

Given

  1. Gradle 6.2.1
  2. id("io.codearte.nexus-staging") version "0.21.2" id("de.marcphilipp.nexus-publish") version "0.4.0"
  3. MultiModule project

Reproducing

  1. Clone repository https://github.com/taymyr/lagom-openapi and checkout to branch nexus_plugins
  2. Remove -SNAPSHOT from version in /build.gradle.kts
  3. Change packageGroup for your.
  4. Run build by command ./gradlew clean publishToSonatype closeRepository -x test
    
    $ ./gradlew clean publishToSonatype closeRepository -x test
    > Task :lagom-openapi-core:dokka
    > Task :scala:lagom-openapi-scala-impl:compileScala
    > Task :scala:lagom-openapi-scala-api:scaladoc
    > Task :scala:lagom-openapi-scala-impl:compileScala
    > Task :scala:lagom-openapi-scala-impl:scaladoc
    > Task :closeRepository
    Requested operation was executed successfully in attempt 6 (maximum allowed 361)
    > Task :scala:lagom-openapi-scala-impl:publishMavenPublicationToSonatypeRepository FAILED

FAILURE: Build failed with an exception.

BUILD FAILED in 6m 16s 61 actionable tasks: 60 executed, 1 up-to-date


## Dry Run

Dry run log is correct and `closeRepository` task is latest.

$ ./gradlew clean publishToSonatype closeRepository --dry-run -x test :clean SKIPPED :lagom-openapi-core:clean SKIPPED :java:lagom-openapi-java-api:clean SKIPPED :java:lagom-openapi-java-impl:clean SKIPPED :scala:lagom-openapi-scala-api:clean SKIPPED :scala:lagom-openapi-scala-impl:clean SKIPPED :java:publishToSonatype SKIPPED :lagom-openapi-core:dokka SKIPPED :lagom-openapi-core:dokkaJar SKIPPED :lagom-openapi-core:compileKotlin SKIPPED :lagom-openapi-core:compileJava SKIPPED :lagom-openapi-core:processResources SKIPPED :lagom-openapi-core:classes SKIPPED :lagom-openapi-core:inspectClassesForKotlinIC SKIPPED :lagom-openapi-core:jar SKIPPED :lagom-openapi-core:generateMetadataFileForMavenPublication SKIPPED :lagom-openapi-core:generatePomFileForMavenPublication SKIPPED :lagom-openapi-core:initializeSonatypeStagingRepository SKIPPED :lagom-openapi-core:sourcesJar SKIPPED :lagom-openapi-core:signMavenPublication SKIPPED :lagom-openapi-core:publishMavenPublicationToSonatypeRepository SKIPPED :lagom-openapi-core:publishToSonatype SKIPPED :scala:publishToSonatype SKIPPED :java:lagom-openapi-java-api:dokka SKIPPED :java:lagom-openapi-java-api:dokkaJar SKIPPED :java:lagom-openapi-java-api:compileKotlin SKIPPED :java:lagom-openapi-java-api:compileJava SKIPPED :java:lagom-openapi-java-api:processResources SKIPPED :java:lagom-openapi-java-api:classes SKIPPED :java:lagom-openapi-java-api:inspectClassesForKotlinIC SKIPPED :java:lagom-openapi-java-api:jar SKIPPED :java:lagom-openapi-java-api:generateMetadataFileForMavenPublication SKIPPED :java:lagom-openapi-java-api:generatePomFileForMavenPublication SKIPPED :java:lagom-openapi-java-api:initializeSonatypeStagingRepository SKIPPED :java:lagom-openapi-java-api:sourcesJar SKIPPED :java:lagom-openapi-java-api:signMavenPublication SKIPPED :java:lagom-openapi-java-api:publishMavenPublicationToSonatypeRepository SKIPPED :java:lagom-openapi-java-api:publishToSonatype SKIPPED :java:lagom-openapi-java-impl:dokka SKIPPED :java:lagom-openapi-java-impl:dokkaJar SKIPPED :java:lagom-openapi-java-impl:compileKotlin SKIPPED :java:lagom-openapi-java-impl:generateLombokConfig SKIPPED :java:lagom-openapi-java-impl:compileJava SKIPPED :java:lagom-openapi-java-impl:processResources SKIPPED :java:lagom-openapi-java-impl:classes SKIPPED :java:lagom-openapi-java-impl:inspectClassesForKotlinIC SKIPPED :java:lagom-openapi-java-impl:jar SKIPPED :java:lagom-openapi-java-impl:generateMetadataFileForMavenPublication SKIPPED :java:lagom-openapi-java-impl:generatePomFileForMavenPublication SKIPPED :java:lagom-openapi-java-impl:initializeSonatypeStagingRepository SKIPPED :java:lagom-openapi-java-impl:sourcesJar SKIPPED :java:lagom-openapi-java-impl:signMavenPublication SKIPPED :java:lagom-openapi-java-impl:publishMavenPublicationToSonatypeRepository SKIPPED :java:lagom-openapi-java-impl:publishToSonatype SKIPPED :scala:lagom-openapi-scala-api:compileJava SKIPPED :scala:lagom-openapi-scala-api:compileScala SKIPPED :scala:lagom-openapi-scala-api:processResources SKIPPED :scala:lagom-openapi-scala-api:classes SKIPPED :scala:lagom-openapi-scala-api:jar SKIPPED :scala:lagom-openapi-scala-api:generateMetadataFileForMavenPublication SKIPPED :scala:lagom-openapi-scala-api:generatePomFileForMavenPublication SKIPPED :scala:lagom-openapi-scala-api:initializeSonatypeStagingRepository SKIPPED :scala:lagom-openapi-scala-api:scaladoc SKIPPED :scala:lagom-openapi-scala-api:scalaDocJar SKIPPED :scala:lagom-openapi-scala-api:sourcesJar SKIPPED :scala:lagom-openapi-scala-api:signMavenPublication SKIPPED :scala:lagom-openapi-scala-api:publishMavenPublicationToSonatypeRepository SKIPPED :scala:lagom-openapi-scala-api:publishToSonatype SKIPPED :scala:lagom-openapi-scala-impl:compileJava SKIPPED :scala:lagom-openapi-scala-impl:compileScala SKIPPED :scala:lagom-openapi-scala-impl:processResources SKIPPED :scala:lagom-openapi-scala-impl:classes SKIPPED :scala:lagom-openapi-scala-impl:jar SKIPPED :scala:lagom-openapi-scala-impl:generateMetadataFileForMavenPublication SKIPPED :scala:lagom-openapi-scala-impl:generatePomFileForMavenPublication SKIPPED :scala:lagom-openapi-scala-impl:initializeSonatypeStagingRepository SKIPPED :scala:lagom-openapi-scala-impl:scaladoc SKIPPED :scala:lagom-openapi-scala-impl:scalaDocJar SKIPPED :scala:lagom-openapi-scala-impl:sourcesJar SKIPPED :scala:lagom-openapi-scala-impl:signMavenPublication SKIPPED :scala:lagom-openapi-scala-impl:publishMavenPublicationToSonatypeRepository SKIPPED :scala:lagom-openapi-scala-impl:publishToSonatype SKIPPED :closeRepository SKIPPED

szpak commented 4 years ago

closeRepository and releaseRepository was originally created as independent tasks to close and release a staging repository. The files could be uploaded in a separate Gradle execution (or in any other way) to create a staging repository which later on would need to be closed (and released).

The usage with nexus-publish improved reliability, but also tighten GNSP's tasks with the publishing process (unless you pass the repository ID from the command line). Most likely, it would be useful to add shouldRunAfter with all the Upload and Publish tasks. Probably, with the way to disable it on demand.

In the meantime, you may want to add it manually in your project.

ihostage commented 4 years ago

@szpak You are absolutely right 👍 And, of course, the next configuration helped me.

tasks.closeRepository {
    mustRunAfter(subprojects.map { it.tasks.getByName("publishToSonatype") }.toTypedArray())
}

But I thought, that this configuration of tasks ordering already implemented in the plugin 😄

vlsi commented 4 years ago

Same here: https://github.com/vlsi/vlsi-release-plugins/blob/6e67690b28ac986f8dc98346f80feebb4aff6082/plugins/stage-vote-release-plugin/src/main/kotlin/com/github/vlsi/gradle/release/StageVoteReleasePlugin.kt#L198-L205

szpak commented 4 years ago

@vlsi You have dependsOn which may be ok for your case, but shouldRunAfter gives an option to still run close or release tasks separately, e.g. if the closing task failed due to timeout and release has to be performed separately (as an emergency operation).

vlsi commented 4 years ago

if the closing task failed due to timeout

If it failed due to timeout, then in 99.84% of the cases it means the operation is in progress at the Nexus side. No retry is required in that case.

In extreme cases, there always is an option to open Nexus UI and release the repository.

Note: closeRepository task itself can't figure out the repository id (yet?) which makes it very very hard to use in isolation.

szpak commented 4 years ago

No retry is required in that case.

Sure, that's why I mentioned close. Usually after some time you can call release.

Note: closeRepository task itself can't figure out the repository id (yet?) which makes it very very hard to use in isolation.

If you have just one, it's not a problem. With the new plugin there is an option to specify the ID.

szpak commented 3 years ago

TL;TD. This case is already improved in gradle-nexus-publish-plugin.

A longer version. To make releasing to Maven Central even easier, I and Marc Phillip (the author of nexus-publish-plugin) combined forces to create a next generation, unified, 2-in-1 plugin - gradle-nexus-publish-plugin. It is a recommended solution, as our development effort will be put in that new plugin. See my blog post and the official migration guide.

ihostage commented 3 years ago

Thank you @szpak! One repo we already migrated to GNPP :+1: