From 821bbceb311a67695e2ae1cb4375a8904f30d0a7 Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Sun, 15 Jan 2023 11:54:16 +0100 Subject: [PATCH 1/2] make finding a staging profile more lenient --- CHANGELOG.md | 4 +++- .../com/vanniktech/maven/publish/nexus/Nexus.kt | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6092d56d..40f7dd53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ ## 0.23.2 **UNRELEASED** -- Fix signing when using the final Gradle 8.0 release. +- Fix signing when using the final Gradle 8.0 release. +- Finding a matching staging profile in Sonatype is more lenient. If there is just one that one will always be used. + The plugin will also fallback to any staging profile that has a matching prefix with the group id. - As a workaround for an issue in Gradle that causes invalid module metadata for `java-test-fixtures` projects, `project.group` and `project.version` are now being set again for those projects. [#490](https://github.com/vanniktech/gradle-maven-publish-plugin/pull/490) diff --git a/nexus/src/main/kotlin/com/vanniktech/maven/publish/nexus/Nexus.kt b/nexus/src/main/kotlin/com/vanniktech/maven/publish/nexus/Nexus.kt index 23c65b0a..9a276233 100644 --- a/nexus/src/main/kotlin/com/vanniktech/maven/publish/nexus/Nexus.kt +++ b/nexus/src/main/kotlin/com/vanniktech/maven/publish/nexus/Nexus.kt @@ -48,12 +48,24 @@ class Nexus( throw IllegalArgumentException("No staging profiles found in account $username. Make sure you called \"./gradlew publish\".") } - val candidateProfiles = allProfiles.filter { group == it.name || group.startsWith(it.name) } + if (allProfiles.size == 1) { + return allProfiles[0] + } + + var candidateProfiles = allProfiles.filter { group == it.name } + + if (candidateProfiles.isEmpty()) { + candidateProfiles = allProfiles.filter { group.startsWith(it.name) } + } + + if (candidateProfiles.isEmpty()) { + candidateProfiles = allProfiles.filter { group.commonPrefixWith(it.name).isNotEmpty() } + } if (candidateProfiles.isEmpty()) { throw IllegalArgumentException( "No matching staging profile found in account $username. It is expected that the account contains a staging " + - "profile that matches or is the start of $group." + + "profile that matches or is the start of $group. " + "Available profiles are: ${allProfiles.joinToString(separator = ", ") { it.name }}" ) } From e2a725f81737b9506d9f5e29fda774f4060fe21e Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Sun, 15 Jan 2023 12:35:19 +0100 Subject: [PATCH 2/2] use ifEmpty --- .../com/vanniktech/maven/publish/nexus/Nexus.kt | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/nexus/src/main/kotlin/com/vanniktech/maven/publish/nexus/Nexus.kt b/nexus/src/main/kotlin/com/vanniktech/maven/publish/nexus/Nexus.kt index 9a276233..73b1acd6 100644 --- a/nexus/src/main/kotlin/com/vanniktech/maven/publish/nexus/Nexus.kt +++ b/nexus/src/main/kotlin/com/vanniktech/maven/publish/nexus/Nexus.kt @@ -52,15 +52,9 @@ class Nexus( return allProfiles[0] } - var candidateProfiles = allProfiles.filter { group == it.name } - - if (candidateProfiles.isEmpty()) { - candidateProfiles = allProfiles.filter { group.startsWith(it.name) } - } - - if (candidateProfiles.isEmpty()) { - candidateProfiles = allProfiles.filter { group.commonPrefixWith(it.name).isNotEmpty() } - } + val candidateProfiles = allProfiles.filter { group == it.name } + .ifEmpty { allProfiles.filter { group.startsWith(it.name) } } + .ifEmpty { allProfiles.filter { group.commonPrefixWith(it.name).isNotEmpty() } } if (candidateProfiles.isEmpty()) { throw IllegalArgumentException(