From 1d521aa93c368b361ac037d4d194a3859860f2ab Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 9 Apr 2021 13:35:31 -0700 Subject: [PATCH] Fix publishing for post-bintray. --- RELEASE_CHECKLIST.md | 10 ------- build.gradle | 5 ++-- gradle/java-publish.gradle | 61 +++++++++++++++++--------------------- 3 files changed, 31 insertions(+), 45 deletions(-) diff --git a/RELEASE_CHECKLIST.md b/RELEASE_CHECKLIST.md index bbecf1f7cd..8eb126f4c7 100644 --- a/RELEASE_CHECKLIST.md +++ b/RELEASE_CHECKLIST.md @@ -14,13 +14,3 @@ We now do this automatically in CI. - `mvn spotless:apply -U` - might take a while for mavencentral to update, the `-U` flag above ensures that it tries again rather than caching a failure - [ ] Comment on all released PRs / issues - -## Stuck release - -Sometimes a release gets stuck. The fix: - -- sync mavencentral manually at bintray.com -- `./gradlew :plugin-gradle:publishPlugins -Prelease=true` if it was a gradle plugin fail -- update `CHANGES.md` manually -- `./gradlew spotlessApply` -- commit, tag, push diff --git a/build.gradle b/build.gradle index 02efb8b73d..269129f36d 100644 --- a/build.gradle +++ b/build.gradle @@ -3,8 +3,8 @@ plugins { id 'com.diffplug.eclipse.resourcefilters' version '3.27.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '0.14.0' apply false - // https://github.com/bintray/gradle-bintray-plugin/releases - id 'com.jfrog.bintray' version '1.8.5' apply false + // https://github.com/gradle-nexus/publish-plugin/releases + id 'io.github.gradle-nexus.publish-plugin' version '1.0.0' apply false // https://github.com/mnlipp/jdrupes-mdoclet/releases id 'org.jdrupes.mdoclet' version '1.0.10' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases @@ -15,6 +15,7 @@ plugins { id "com.diffplug.spotless-changelog" version "2.1.0" apply false } +apply from: rootProject.file('gradle/java-publish.gradle') apply from: rootProject.file('gradle/changelog.gradle') allprojects { apply from: rootProject.file('gradle/spotless.gradle') diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 15e9562633..bca0ba15f2 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -1,8 +1,29 @@ + +if (project.parent == null) { + // it's the root project + apply plugin: 'io.github.gradle-nexus.publish-plugin' + nexusPublishing { + repositories { + sonatype { + username = System.env['nexus_user'] + password = System.env['nexus_pass'] + } + } + } + def initTask = tasks.named('initializeSonatypeStagingRepository') + allprojects { + initTask.configure { + shouldRunAfter(tasks.withType(Sign)) + } + } + return +} + /////////// // MAVEN // /////////// apply plugin: 'maven-publish' -apply plugin: 'com.jfrog.bintray' +apply plugin: 'signing' task sourcesJar(type: Jar) { classifier = 'sources' @@ -138,36 +159,11 @@ model { } if (!version.endsWith('-SNAPSHOT')) { - // upload releases to bintray and then mavenCentral - bintray { - user = System.env['bintray_user'] - key = System.env['bintray_pass'] - publications = [ - 'pluginMaven' - ] - publish = true - pkg { - repo = 'opensource' - name = project.ext.artifactId - userOrg = project.org - version { - name = project.version - mavenCentralSync { - user = System.env['nexus_user'] - password = System.env['nexus_pass'] - } - } - } + signing { + useInMemoryPgpKeys(System.env['gpg_key'], System.env['gpg_passphrase']) + sign(publishing.publications) } - publish.dependsOn(bintrayUpload) - bintrayUpload.dependsOn([ - 'generatePomFileForPluginMavenPublication', - jar, - sourcesJar, - javadocJar - ]) - // find the project with the changelog (this project for plugins, root project for libs) def changelogTasks = (tasks.names.contains('changelogBump') ? project : rootProject).tasks @@ -177,10 +173,9 @@ if (!version.endsWith('-SNAPSHOT')) { } // ensures that changelog bump and push only happens if the publish was successful changelogTasks.named('changelogBump').configure { - dependsOn tasks.named('bintrayUpload') - // only the root project has bintrayPublish, and it finalizes all bintrayUpload tasks - // https://github.com/bintray/gradle-bintray-plugin/blob/3fe02dfdae3e807afba57e0140a0d4c2424674e1/src/main/groovy/com/jfrog/bintray/gradle/ProjectsEvaluatedBuildListener.groovy#L37-L41 - dependsOn rootProject.tasks.named('bintrayPublish') + String pubName = plugins.hasPlugin('java-gradle-plugin') ? 'PluginMaven' : 'MavenJava' + dependsOn tasks.named("publish${pubName}PublicationToSonatypeRepository") + dependsOn rootProject.tasks.named('closeAndReleaseSonatypeStagingRepository') // if we have a gradle plugin, we need to push it up to the plugin portal too if (tasks.names.contains('publishPlugins')) { dependsOn tasks.named('publishPlugins')