diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1385a46..c9ef5f9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,10 +46,8 @@ publish-maven:gitlab: interruptible: false rules: - - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + - if: $PUBLISH_MAVEN == "no" || $PUBLISH_MAVEN_GITLAB == "no" when: never - - if: $PUBLISH_MAVEN == "manual" || $PUBLISH_MAVEN_GITLAB == "manual" - when: manual - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH - if: $CI_COMMIT_TAG @@ -67,12 +65,10 @@ publish-maven:central: interruptible: false rules: - - if: $CI_PIPELINE_SOURCE == 'merge_request_event' - when: never - if: $OSSRH_USERNAME == null || $OSSRH_PASSWORD == null when: never - - if: $PUBLISH_MAVEN == "manual" || $PUBLISH_MAVEN_CENTRAL == "manual" - when: manual + - if: $PUBLISH_MAVEN == "no" || $PUBLISH_MAVEN_CENTRAL == "no" + when: never - if: $CI_COMMIT_TAG # endregion -- 2.51.2 From ebabee578cdc90d3cbd26fef11df2de0523f774a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sun, 24 Sep 2023 21:46:53 +0200 Subject: [PATCH 2/8] build: Use the Gradle Nexus Publish plugin to fix Central staging repository splitting --- .gitlab-ci.yml | 41 ++++++++++++++++++- build.gradle.kts | 3 ++ .../src/main/kotlin/library.gradle.kts | 11 ----- gradle/conventions/root/build.gradle.kts | 9 ++++ .../root/src/main/kotlin/root.gradle.kts | 17 ++++++++ gradle/conventions/settings.gradle.kts | 1 + gradle/libs.versions.toml | 1 + 7 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 gradle/conventions/root/build.gradle.kts create mode 100644 gradle/conventions/root/src/main/kotlin/root.gradle.kts diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c9ef5f9..c5508b2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -51,16 +51,53 @@ publish-maven:gitlab: - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH - if: $CI_COMMIT_TAG +publish-maven:central:initialize: + extends: [ .os.gradle ] + needs: [ os.version ] + stage: deploy + + script: + - > + ./gradlew initializeSonatypeStagingRepository + -PappVersion=$project_version + + interruptible: false + rules: + - if: $OSSRH_USERNAME == null || $OSSRH_PASSWORD == null + when: never + - if: $PUBLISH_MAVEN == "no" || $PUBLISH_MAVEN_CENTRAL == "no" + when: never + - if: $CI_COMMIT_TAG + publish-maven:central: extends: [ .os.gradle ] - needs: [ os.version, check ] + needs: [ os.version, publish-maven:central:initialize ] stage: deploy script: - export SIGNING_KEY_RING=$(mktemp) - <"$SIGNING_KEY_RING_B64" base64 -d >"$SIGNING_KEY_RING" - > - ./gradlew publishAllPublicationsToCentralRepository + ./gradlew findSonatypeStagingRepository publishToSonatype + -x initializeSonatypeStagingRepository + -PappVersion=$project_version + + interruptible: false + rules: + - if: $OSSRH_USERNAME == null || $OSSRH_PASSWORD == null + when: never + - if: $PUBLISH_MAVEN == "no" || $PUBLISH_MAVEN_CENTRAL == "no" + when: never + - if: $CI_COMMIT_TAG + +publish-maven:central:close: + extends: [ .os.gradle ] + needs: [ os.version, publish-maven:central ] + stage: deploy + + script: + - > + ./gradlew findSonatypeStagingRepository closeSonatypeStagingRepository -PappVersion=$project_version interruptible: false diff --git a/build.gradle.kts b/build.gradle.kts index 9bec650..67bd65f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,6 +8,9 @@ */ plugins { + id("conventions.base") + id("conventions.root") + // Some plugins *must* be configured on the root project. // In these cases, we explicitly tell Gradle not to apply them. alias(libs.plugins.kotlin) apply false diff --git a/gradle/conventions/library/src/main/kotlin/library.gradle.kts b/gradle/conventions/library/src/main/kotlin/library.gradle.kts index 3c549e5..0ac7f68 100644 --- a/gradle/conventions/library/src/main/kotlin/library.gradle.kts +++ b/gradle/conventions/library/src/main/kotlin/library.gradle.kts @@ -83,17 +83,6 @@ val fakeJavadocJar by tasks.registering(Jar::class) { } publishing { - repositories { - maven { - name = "Central" - url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") - credentials { - username = System.getenv("OSSRH_USERNAME") - password = System.getenv("OSSRH_PASSWORD") - } - } - } - publications.withType { artifact(fakeJavadocJar.get()) diff --git a/gradle/conventions/root/build.gradle.kts b/gradle/conventions/root/build.gradle.kts new file mode 100644 index 0000000..555f094 --- /dev/null +++ b/gradle/conventions/root/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + `kotlin-dsl` +} + +group = "conventions" + +dependencies { + implementation(libs.gradle.nexusPublish) +} diff --git a/gradle/conventions/root/src/main/kotlin/root.gradle.kts b/gradle/conventions/root/src/main/kotlin/root.gradle.kts new file mode 100644 index 0000000..2352c59 --- /dev/null +++ b/gradle/conventions/root/src/main/kotlin/root.gradle.kts @@ -0,0 +1,17 @@ +package conventions + +plugins { + id("io.github.gradle-nexus.publish-plugin") +} + +nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + + username.set(System.getenv("OSSRH_USERNAME")) + password.set(System.getenv("OSSRH_PASSWORD")) + } + } +} diff --git a/gradle/conventions/settings.gradle.kts b/gradle/conventions/settings.gradle.kts index d143d50..71aee0e 100644 --- a/gradle/conventions/settings.gradle.kts +++ b/gradle/conventions/settings.gradle.kts @@ -15,6 +15,7 @@ dependencyResolutionManagement { include( "base", + "root", "kotlin", "library", ) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5a1c3e5..157d43b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,3 +9,4 @@ kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = # To use existing plugins in convention plugins, we must also declare them as libraries gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } +gradle-nexusPublish = { module = "io.github.gradle-nexus:publish-plugin", version = "1.3.0" } -- 2.51.2 From 2ddcbe46c4b5c3a269796ead235410938ba21a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sun, 24 Sep 2023 22:04:50 +0200 Subject: [PATCH 3/8] build: Rename the Gradle group to align it with our MavenCentral credentials --- gradle/conventions/base/src/main/kotlin/base.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/conventions/base/src/main/kotlin/base.gradle.kts b/gradle/conventions/base/src/main/kotlin/base.gradle.kts index 3ca9d87..41cb074 100644 --- a/gradle/conventions/base/src/main/kotlin/base.gradle.kts +++ b/gradle/conventions/base/src/main/kotlin/base.gradle.kts @@ -6,5 +6,5 @@ plugins { val appVersion: String? by project -group = "opensavvy.playground" +group = "dev.opensavvy.playground" version = appVersion ?: "0.0.0-DEV" -- 2.51.2 From 1dd6edbe00fff54ad025826282bab0324fb79b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sun, 24 Sep 2023 22:05:21 +0200 Subject: [PATCH 4/8] build: Crash if someone forgot to change the group when importing the project --- gradle/conventions/base/src/main/kotlin/base.gradle.kts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gradle/conventions/base/src/main/kotlin/base.gradle.kts b/gradle/conventions/base/src/main/kotlin/base.gradle.kts index 41cb074..013cb0f 100644 --- a/gradle/conventions/base/src/main/kotlin/base.gradle.kts +++ b/gradle/conventions/base/src/main/kotlin/base.gradle.kts @@ -8,3 +8,12 @@ val appVersion: String? by project group = "dev.opensavvy.playground" version = appVersion ?: "0.0.0-DEV" + +// region Check the users of the project didn't forget to rename the group + +val projectPath: String? = System.getenv("CI_PROJECT_PATH") +if (projectPath != null && projectPath != "opensavvy/playgrounds/gradle" && group == "dev.opensavvy.playground") { + error("The project is declared to be in the group '$group', which is recognized as the Gradle Playground, but it's hosted in '$projectPath', which is not the Playground. Maybe you forgot to rename the group when importing the Playground in your own project?") +} + +// endregion -- 2.51.2 From e9d5b15937f98bfba4029400d0d278038606ac6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sun, 24 Sep 2023 22:16:10 +0200 Subject: [PATCH 5/8] build: Disable the configuration cache for publishing jobs --- .gitlab-ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c5508b2..f5ae7d5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,6 +42,7 @@ publish-maven:gitlab: script: - > ./gradlew publishAllPublicationsToGitLabRepository + --no-configuration-cache -PappVersion=$project_version interruptible: false @@ -59,6 +60,7 @@ publish-maven:central:initialize: script: - > ./gradlew initializeSonatypeStagingRepository + --no-configuration-cache -PappVersion=$project_version interruptible: false @@ -80,6 +82,7 @@ publish-maven:central: - > ./gradlew findSonatypeStagingRepository publishToSonatype -x initializeSonatypeStagingRepository + --no-configuration-cache -PappVersion=$project_version interruptible: false @@ -98,6 +101,7 @@ publish-maven:central:close: script: - > ./gradlew findSonatypeStagingRepository closeSonatypeStagingRepository + --no-configuration-cache -PappVersion=$project_version interruptible: false -- 2.51.2 From a8a4773b8343d7ae2905b000a0808ab13012d4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Wed, 27 Sep 2023 22:05:39 +0200 Subject: [PATCH 6/8] build(gradle): Configure the 'core' project with the necessary metadata for Central --- core/build.gradle.kts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index d847522..42ac38d 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -7,3 +7,9 @@ plugins { kotlin { jvm() } + +library { + name.set("Playground Core") + description.set("Project template with configured MavenCentral publication") + homeUrl.set("https://gitlab.com/opensavvy/playgrounds/gradle") +} -- 2.51.2 From aa26022beb320cfe25b5b1c9e3dc6890c981a7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Wed, 27 Sep 2023 22:06:04 +0200 Subject: [PATCH 7/8] build(gradle): Automatically set the Central SCM URL from the GitLab predefined variables --- gradle/conventions/library/src/main/kotlin/library.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/conventions/library/src/main/kotlin/library.gradle.kts b/gradle/conventions/library/src/main/kotlin/library.gradle.kts index 0ac7f68..1986fdb 100644 --- a/gradle/conventions/library/src/main/kotlin/library.gradle.kts +++ b/gradle/conventions/library/src/main/kotlin/library.gradle.kts @@ -29,7 +29,7 @@ fun MavenPom.buildConfiguration() { } scm { - url.set("https://gitlab.com/opensavvy/playgrounds/gradle") + url.set(System.getenv("CI_PROJECT_URL")) } } -- 2.51.2 From f049d7807e05653206b0b0c0dabc5b4ec06e1ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Wed, 27 Sep 2023 22:11:51 +0200 Subject: [PATCH 8/8] build(gradle): More precise description to avoid duplications --- gradle/conventions/root/src/main/kotlin/root.gradle.kts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gradle/conventions/root/src/main/kotlin/root.gradle.kts b/gradle/conventions/root/src/main/kotlin/root.gradle.kts index 2352c59..abf742d 100644 --- a/gradle/conventions/root/src/main/kotlin/root.gradle.kts +++ b/gradle/conventions/root/src/main/kotlin/root.gradle.kts @@ -5,6 +5,11 @@ plugins { } nexusPublishing { + val projectPath = System.getenv("CI_PROJECT_PATH_SLUG") + val refSlug = System.getenv("CI_COMMIT_REF_SLUG") + val pipelineId = System.getenv("CI_PIPELINE_IID") + repositoryDescription.set("$projectPath for $refSlug (pipeline $pipelineId)") // must be globally unique for a pipeline to avoid issues with concurrent builds + repositories { sonatype { nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))