Skip to content

Commit

Permalink
fix split repos when publishing to Sonatype Nexus
Browse files Browse the repository at this point in the history
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 gradle/gradle#5711

Signed-off-by: Peter Gafert <[email protected]>
  • Loading branch information
codecholeric committed May 23, 2020
1 parent 2b84aaf commit 00ea9ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
22 changes: 6 additions & 16 deletions build-steps/release/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 00ea9ed

Please sign in to comment.