From 046b93fd0b0a8efa625a848cbb1f278c1dbfcbbf Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Thu, 26 May 2022 16:50:53 +0800 Subject: [PATCH] Move Sonatyp OSSRH publish code here from "kotlin-common" and adapt into script plugins --- .../main/kotlin/plugin-conventions.gradle.kts | 2 +- kotlin-common-gradle-plugins/build.gradle.kts | 9 +++++++++ ...atype-ossrh-publish-conventions.gradle.kts | 6 ++++++ ...fault-maven-publish-conventions.gradle.kts | 13 ++---------- ...atype-ossrh-publish-conventions.gradle.kts | 14 +++++++++++++ .../com/huanshankeji/nexus-staging.gradle.kts | 14 +++++++++++++ .../sonatype-ossrh-publish.gradle.kts | 20 +++++++++++++++++++ 7 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-sonatype-ossrh-publish-conventions.gradle.kts create mode 100644 kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-sonatype-ossrh-publish-conventions.gradle.kts create mode 100644 kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/nexus-staging.gradle.kts create mode 100644 kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/sonatype-ossrh-publish.gradle.kts diff --git a/buildSrc/src/main/kotlin/plugin-conventions.gradle.kts b/buildSrc/src/main/kotlin/plugin-conventions.gradle.kts index bed5f2a..90d671f 100644 --- a/buildSrc/src/main/kotlin/plugin-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/plugin-conventions.gradle.kts @@ -8,7 +8,7 @@ dependencies { implementation(kotlin("gradle-plugin", "1.6.10")) } -version = "0.1.2-kotlin-1.6.10-SNAPSHOT" +version = "0.1.3-kotlin-1.6.10-SNAPSHOT" pluginBundle { website = "https://github.com/huanshankeji/gradle-plugin" diff --git a/kotlin-common-gradle-plugins/build.gradle.kts b/kotlin-common-gradle-plugins/build.gradle.kts index 20c8d87..ef6fa11 100644 --- a/kotlin-common-gradle-plugins/build.gradle.kts +++ b/kotlin-common-gradle-plugins/build.gradle.kts @@ -4,6 +4,7 @@ plugins { dependencies { //api(project(":common-gradle-dependencies")) + //implementation("io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0") } gradlePlugin { @@ -38,5 +39,13 @@ gradlePlugin { "kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions", "Kotlin Multiplatform conventions with the JVM target and the JS browser target, and with default Maven publish" ) + scriptConventionsPlugin( + "kotlin-jvm-library-sonatype-ossrh-publish-conventions", + "Kotlin/JVM library conventions with Sonatype OSSRH Maven Central publish" + ) + scriptConventionsPlugin( + "kotlin-multiplatform-jvm-and-js-browser-sonatype-ossrh-publish-conventions", + "Kotlin Multiplatform conventions with the JVM target and the JS browser target, and with Sonatype OSSRH Maven Central publish" + ) } } diff --git a/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-sonatype-ossrh-publish-conventions.gradle.kts b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-sonatype-ossrh-publish-conventions.gradle.kts new file mode 100644 index 0000000..0c52912 --- /dev/null +++ b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-sonatype-ossrh-publish-conventions.gradle.kts @@ -0,0 +1,6 @@ +package com.huanshankeji + +plugins { + id("com.huanshankeji.kotlin-jvm-library-default-maven-publish-conventions") + id("com.huanshankeji.sonatype-ossrh-publish") +} diff --git a/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions.gradle.kts b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions.gradle.kts index 5e26175..7c8a756 100644 --- a/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions.gradle.kts +++ b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions.gradle.kts @@ -5,15 +5,6 @@ plugins { id("com.huanshankeji.default-maven-publish") } -val javadocJar by tasks.registering(Jar::class) { - archiveClassifier.set("javadoc") -} - -publishing { - publications { - withType { - artifactId = "$defaultPrefixForPublishing-$artifactId" - artifact(javadocJar) - } - } +publishing.publications.withType { + artifactId = "$defaultPrefixForPublishing-$artifactId" } diff --git a/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-sonatype-ossrh-publish-conventions.gradle.kts b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-sonatype-ossrh-publish-conventions.gradle.kts new file mode 100644 index 0000000..2de2905 --- /dev/null +++ b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-sonatype-ossrh-publish-conventions.gradle.kts @@ -0,0 +1,14 @@ +package com.huanshankeji + +plugins { + id("com.huanshankeji.kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions") + id("com.huanshankeji.sonatype-ossrh-publish") +} + +val javadocJar by tasks.registering(Jar::class) { + archiveClassifier.set("javadoc") +} + +publishing.publications.withType { + artifact(javadocJar) +} diff --git a/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/nexus-staging.gradle.kts b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/nexus-staging.gradle.kts new file mode 100644 index 0000000..ac81c71 --- /dev/null +++ b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/nexus-staging.gradle.kts @@ -0,0 +1,14 @@ +package com.huanshankeji + +/* TODO: this script is not working yet. +plugins { + id("io.codearte.nexus-staging") +} + +group = "com.huanshankeji" + +nexusStaging { + serverUrl = "https://s01.oss.sonatype.org/service/local/" + // TODO +} +*/ diff --git a/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/sonatype-ossrh-publish.gradle.kts b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/sonatype-ossrh-publish.gradle.kts new file mode 100644 index 0000000..0f5151c --- /dev/null +++ b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/sonatype-ossrh-publish.gradle.kts @@ -0,0 +1,20 @@ +package com.huanshankeji + +plugins { + id("com.huanshankeji.default-maven-publish") + signing +} + +signing { + sign(publishing.publications) +} + +publishing.repositories.maven { + val releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + val snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" + url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl) + credentials { + username = project.property("ossrhUsername") as String + password = project.property("ossrhPassword") as String + } +}