From 00ea9edb80ccf61a02244598665fb22c3626bce4 Mon Sep 17 00:00:00 2001 From: Peter Gafert Date: Sun, 24 May 2020 01:16:21 +0200 Subject: [PATCH] fix split repos when publishing to Sonatype Nexus Unfortunately the Gradle Publish Plugin behaves erratically in combination with Sonatype Nexus. In particular if timing is bad, split repositories will be created. The only way I could find to mitigate this problem is the `de.marcphilipp.nexus-publish` plugin, which will create a Sonatype repository in a pre-step, then publish all artifacts to this repository. As far as I could see it works fine for releases and snapshots, has a shorter config and solves the problem at hand. Also compare https://github.com/gradle/gradle/issues/5711 Signed-off-by: Peter Gafert --- build-steps/release/publish.gradle | 22 ++++++---------------- build.gradle | 1 + 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/build-steps/release/publish.gradle b/build-steps/release/publish.gradle index 008de19ad2..c7936a6a8b 100644 --- a/build-steps/release/publish.gradle +++ b/build-steps/release/publish.gradle @@ -10,6 +10,7 @@ if (!hasProperty("sonatypePassword")) { releaseProjects*.with { apply plugin: "maven-publish" apply plugin: "signing" + apply plugin: "de.marcphilipp.nexus-publish" tasks.withType(GenerateModuleMetadata) { enabled = false // the meta-data does not match the way the Maven artifacts are composed and thus is broken @@ -82,22 +83,11 @@ releaseProjects*.with { } } - repositories { - // respective username and password can be configured in ~/.gradle/gradle.properties - if (project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')) { - maven { - def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" - def snapshotRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/" - url = isReleaseVersion ? releasesRepoUrl : snapshotRepoUrl - - credentials { - username = sonatypeUsername - password = sonatypePassword - } - - metadataSources { - gradleMetadata() - } + // respective username and password can be configured in ~/.gradle/gradle.properties + if (project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')) { + nexusPublishing { + repositories { + sonatype() } } } diff --git a/build.gradle b/build.gradle index 13bdc6e106..cdcda0e8c9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id 'com.github.johnrengelman.shadow' version '5.2.0' apply false id 'com.github.spotbugs' version '4.0.5' apply false + id "de.marcphilipp.nexus-publish" version "0.4.0" apply false } def appAndSourceUrl = 'https://github.com/TNG/ArchUnit'