From fd2491cb30b508e8d9a10597ce4e2130c7f02b84 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Wed, 22 May 2024 22:50:48 +0300 Subject: [PATCH] use `gradle-maven-publish-plugin` as it creates staging repository itself and doesn't rely on auto-staging (#273) --- .github/workflows/publish-release.yml | 20 +-- .github/workflows/publish-snapshot.yml | 12 +- build-logic/build.gradle.kts | 1 + .../rsocketbuild.publication.gradle.kts | 118 ++++++------------ gradle.properties | 2 +- gradle/libs.versions.toml | 3 + 6 files changed, 56 insertions(+), 100 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index a939b0bd..81457cd9 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -16,18 +16,10 @@ jobs: with: cache-disabled: true - - name: Publish to Maven Local (prepare packages) - run: ./gradlew publishToMavenLocal -Pversion=${{ github.ref_name }} --no-configuration-cache + - name: Publish release to Maven Central + run: ./gradlew publishToMavenCentral -Pversion=${{ github.ref_name }} --no-configuration-cache env: - ORG_GRADLE_PROJECT_signingKey: ${{secrets.signingKey}} - ORG_GRADLE_PROJECT_signingPassword: ${{secrets.signingPassword}} - ORG_GRADLE_PROJECT_sonatypeUsername: ${{secrets.sonatypeUsername}} - ORG_GRADLE_PROJECT_sonatypePassword: ${{secrets.sonatypePassword}} - - - name: Publish release to Maven Central (version ${{ github.ref_name }}) - run: ./gradlew publishAllPublicationsToSonatypeRepository -Pversion=${{ github.ref_name }} --no-configuration-cache - env: - ORG_GRADLE_PROJECT_signingKey: ${{secrets.signingKey}} - ORG_GRADLE_PROJECT_signingPassword: ${{secrets.signingPassword}} - ORG_GRADLE_PROJECT_sonatypeUsername: ${{secrets.sonatypeUsername}} - ORG_GRADLE_PROJECT_sonatypePassword: ${{secrets.sonatypePassword}} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{secrets.signingKey}} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{secrets.signingPassword}} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{secrets.sonatypeUsername}} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{secrets.sonatypePassword}} diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml index 4f00a8e0..b880aec3 100644 --- a/.github/workflows/publish-snapshot.yml +++ b/.github/workflows/publish-snapshot.yml @@ -27,8 +27,10 @@ jobs: branch_name="${ref_name////-}" echo "::set-output name=version-suffix::$branch_name" - - name: Publish to Maven Local (prepare packages) - run: ./gradlew publishToMavenLocal -PversionSuffix=${{ steps.set-version.outputs.version-suffix }} -PgithubUsername=${{ github.actor }} -PgithubPassword=${{ github.token }} --no-configuration-cache - - - name: Publish snapshot to Github Packages (version x.y.z-${{ steps.set-version.outputs.version-suffix }}-SNAPSHOT) - run: ./gradlew publishAllPublicationsToGithubRepository -PversionSuffix=${{ steps.set-version.outputs.version-suffix }} -PgithubUsername=${{ github.actor }} -PgithubPassword=${{ github.token }} --no-configuration-cache + - name: Publish snapshot to Maven Central + run: ./gradlew publishToMavenCentral -Pversion=0.16.0-${{ steps.set-version.outputs.version-suffix }}-SNAPSHOT --no-configuration-cache + env: + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{secrets.signingKey}} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{secrets.signingPassword}} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{secrets.sonatypeUsername}} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{secrets.sonatypePassword}} diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 7a6b5f1a..4ae83233 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -22,4 +22,5 @@ dependencies { implementation(libs.kotlin.gradle.plugin) implementation(libs.kotlinx.bcv.gradle.plugin) implementation(libs.kotlinx.atomicfu.gradle.plugin) + implementation(libs.maven.publish.gradle.plugin) } diff --git a/build-logic/src/main/kotlin/rsocketbuild.publication.gradle.kts b/build-logic/src/main/kotlin/rsocketbuild.publication.gradle.kts index b06a1045..6e956961 100644 --- a/build-logic/src/main/kotlin/rsocketbuild.publication.gradle.kts +++ b/build-logic/src/main/kotlin/rsocketbuild.publication.gradle.kts @@ -14,96 +14,54 @@ * limitations under the License. */ -plugins { - `maven-publish` - signing -} - -val githubUsername: String? by project -val githubPassword: String? by project - -val sonatypeUsername: String? by project -val sonatypePassword: String? by project - -val signingKey: String? by project -val signingPassword: String? by project +import com.vanniktech.maven.publish.* -// TODO: refactor publication a bit, so that version in gradle.properties will not contain SNAPSHOT -val versionSuffix = providers.gradleProperty("rsocketbuild.versionSuffix").orNull -if (versionSuffix != null) { - val versionString = project.version.toString() - require(versionString.endsWith("-SNAPSHOT")) - project.version = versionString.replace("-", "-${versionSuffix}-") - println("Current version: ${project.version}") +plugins { + id("com.vanniktech.maven.publish.base") } -// empty javadoc for maven central -val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") } - -// this is somewhat a hack because we have a single javadoc artifact which is used for all publications -tasks.withType().configureEach { dependsOn(javadocJar) } -tasks.withType().configureEach { dependsOn(tasks.withType()) } +mavenPublishing { + publishToMavenCentral(SonatypeHost.S01) + signAllPublications() -publishing { - publications.withType { - artifact(javadocJar) - pom { - name.set(project.name) - description.set(provider { - checkNotNull(project.description) { "Project description isn't set for project: ${project.path}" } - }) - url.set("http://rsocket.io") + pom { + name.set(project.name) + description.set(provider { + checkNotNull(project.description) { "Project description isn't set for project: ${project.path}" } + }) + url.set("https://rsocket.io") - licenses { - license { - name.set("The Apache Software License, Version 2.0") - url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") - distribution.set("repo") - } - } - developers { - developer { - id.set("whyoleg") - name.set("Oleg Yukhnevich") - email.set("whyoleg@gmail.com") - } - developer { - id.set("OlegDokuka") - name.set("Oleh Dokuka") - email.set("oleh.dokuka@icloud.com") - } - } - scm { - connection.set("https://github.com/rsocket/rsocket-kotlin.git") - developerConnection.set("https://github.com/rsocket/rsocket-kotlin.git") - url.set("https://github.com/rsocket/rsocket-kotlin") + licenses { + license { + name.set("The Apache Software License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("repo") } } - } - - repositories { - // TODO: drop github and use sonatype (?) - maven { - name = "github" - url = uri("https://maven.pkg.github.com/rsocket/rsocket-kotlin") - credentials { - username = githubUsername - password = githubPassword + developers { + developer { + id.set("whyoleg") + name.set("Oleg Yukhnevich") + email.set("whyoleg@gmail.com") } - } - maven { - name = "sonatype" - url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2") - credentials { - username = sonatypeUsername - password = sonatypePassword + developer { + id.set("OlegDokuka") + name.set("Oleh Dokuka") + email.set("oleh.dokuka@icloud.com") } } + scm { + connection.set("https://github.com/rsocket/rsocket-kotlin.git") + developerConnection.set("https://github.com/rsocket/rsocket-kotlin.git") + url.set("https://github.com/rsocket/rsocket-kotlin") + } } } -signing { - isRequired = sonatypeUsername != null && sonatypePassword != null - useInMemoryPgpKeys(signingKey, signingPassword) - sign(publishing.publications) -} +// javadocJar setup +// we have a single javadoc artifact which is used for all publications, +// and so we need to manually create task dependencies to make Gradle happy +val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") } +tasks.withType().configureEach { dependsOn(javadocJar) } +tasks.withType().configureEach { dependsOn(tasks.withType()) } +publishing.publications.withType().configureEach { artifact(javadocJar) } diff --git a/gradle.properties b/gradle.properties index 73e9e242..b86b6a11 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ # limitations under the License. # group=io.rsocket.kotlin -version=0.16.0-SNAPSHOT +version=0.16.0 #Kotlin kotlin.mpp.import.enableKgpDependencyResolution=true kotlin.native.ignoreDisabledTargets=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a05570bf..ab19c0aa 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,6 +14,8 @@ rsocket-java = "1.1.3" jmh = "1.36" +maven-publish = "0.28.0" + [libraries] kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" } @@ -45,6 +47,7 @@ rsocket-java-transport-local = { module = 'io.rsocket:rsocket-transport-local', kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } kotlinx-atomicfu-gradle-plugin = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "kotlinx-atomicfu" } kotlinx-bcv-gradle-plugin = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "kotlinx-bcv" } +maven-publish-gradle-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "maven-publish" } [plugins] kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }