From f020d0dc1fdf4aca49519f05ca18186f6a5a0546 Mon Sep 17 00:00:00 2001 From: Leon Kiefer Date: Mon, 25 Mar 2024 16:03:58 +0100 Subject: [PATCH] Use gradle-nexus.publish-plugin --- .github/workflows/ci.yml | 9 -- .github/workflows/publish.yml | 12 +- .gitignore | 2 +- build.gradle.kts | 91 +------------- convention-plugins/build.gradle.kts | 13 ++ .../kotlin/convention.publication.gradle.kts | 113 ++++++++++++++++++ 6 files changed, 133 insertions(+), 107 deletions(-) create mode 100644 convention-plugins/build.gradle.kts create mode 100644 convention-plugins/src/main/kotlin/convention.publication.gradle.kts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 463b3f4..0789f19 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,12 +48,3 @@ jobs: with: job-id: jdk8-build-test arguments: build -x test - - - name: Publish Maven (Snapshot) - uses: burrunan/gradle-cache-action@v1 - with: - job-id: jdk8-build-test - arguments: publishMavenRelease - properties: | - ossrhUsername=${{ secrets.OSSRH_USERNAME }} - ossrhPassword=${{ secrets.OSSRH_PASSWORD }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 279154c..4ad4379 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -26,15 +26,13 @@ jobs: - name: Publish Maven uses: burrunan/gradle-cache-action@v1 env: - ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_SIGNING_KEY }} - ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }} + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + SIGNING_SIGNING_KEY: ${{ secrets.SIGNING_SIGNING_KEY }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} with: job-id: jdk8-build-test arguments: >- - build - publishRelease - -x test + publishAllPublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository properties: | releaseVersion=${{ steps.tagName.outputs.tag }} - ossrhUsername=${{ secrets.OSSRH_USERNAME }} - ossrhPassword=${{ secrets.OSSRH_PASSWORD }} diff --git a/.gitignore b/.gitignore index 7a3d207..33e01e2 100644 --- a/.gitignore +++ b/.gitignore @@ -137,4 +137,4 @@ gradle-app.setting run /.idea -/bin +bin/ diff --git a/build.gradle.kts b/build.gradle.kts index f15cfd3..2d7d552 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -108,112 +108,23 @@ tasks { } } - -// -// DOCS -// - -tasks { - dokkaHtml { - outputDirectory.set(file("$buildDir/javadoc/$releaseVersion")) - } - - javadoc { - dependsOn(dokkaHtml) - } -} - // // PUBLISHING // publishing { - publications { - - create("library") { + create("maven") { from(components["java"]) pom { name.set("TypeScript Poet") description.set("TypeScriptPoet is a Kotlin and Java API for generating .ts source files.") - url.set("https://github.com/voize-gmbh/typescriptpoet") - - scm { - url.set("https://github.com/voize-gmbh/reakt-native-toolkit") - } - - licenses { - license { - name.set("Apache-2.0") - url.set("https://opensource.org/licenses/Apache-2.0") - } - } - developers { - developer { - id.set("LeonKiefer") - name.set("Leon Kiefer") - email.set("leon@voize.de") - } - developer { - id.set("ErikZiegler") - name.set("Erik Ziegler") - email.set("erik@voize.de") - } - } - } - } - } - - repositories { - - maven { - name = "MavenCentral" - val snapshotUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" - val releaseUrl = "https://s01.oss.sonatype.org/service/local/" - url = uri(if (isSnapshot) snapshotUrl else releaseUrl) - - credentials { - username = project.findProperty("ossrhUsername")?.toString() - password = project.findProperty("ossrhPassword")?.toString() } } - - } - -} - -signing { - if (!hasProperty("signing.keyId")) { - val signingKey: String? by project - val signingPassword: String? by project - useInMemoryPgpKeys(signingKey, signingPassword) } - sign(publishing.publications["library"]) } tasks.withType().configureEach { onlyIf { !isSnapshot } } - - -// -// RELEASING -// - - -tasks { - - register("publishMavenRelease") { - dependsOn( - "publishAllPublicationsToMavenCentralRepository" - ) - } - - register("publishRelease") { - dependsOn( - "publishMavenRelease", - ) - } - -} diff --git a/convention-plugins/build.gradle.kts b/convention-plugins/build.gradle.kts new file mode 100644 index 0000000..4853850 --- /dev/null +++ b/convention-plugins/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + `kotlin-dsl` +} + +dependencies { + implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.9.10") + implementation("io.github.gradle-nexus:publish-plugin:1.1.0") +} + +repositories { + gradlePluginPortal() + mavenCentral() +} diff --git a/convention-plugins/src/main/kotlin/convention.publication.gradle.kts b/convention-plugins/src/main/kotlin/convention.publication.gradle.kts new file mode 100644 index 0000000..f2c2490 --- /dev/null +++ b/convention-plugins/src/main/kotlin/convention.publication.gradle.kts @@ -0,0 +1,113 @@ +import java.util.* + +plugins { + `maven-publish` + signing + id("org.jetbrains.dokka") + id("io.github.gradle-nexus.publish-plugin") +} + +val signingKey: String? = System.getenv("SIGNING_SIGNING_KEY") +val signingPassword: String? = System.getenv("SIGNING_PASSWORD") + +// Stub secrets to let the project sync and build without the publication values set up +ext["ossrhUsername"] = null +ext["ossrhPassword"] = null + +// Grabbing secrets from local.properties file or from environment variables, which could be used on CI +val secretPropsFile = project.rootProject.file("local.properties") +if (secretPropsFile.exists()) { + secretPropsFile.reader().use { + Properties().apply { + load(it) + } + }.onEach { (name, value) -> + ext[name.toString()] = value + } +} else { + ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME") + ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD") +} + +fun getExtraString(name: String) = ext[name]?.toString() + +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(getExtraString("ossrhUsername")) + password.set(getExtraString("ossrhPassword")) + } + } +} + +subprojects { + apply(plugin = "org.jetbrains.dokka") + apply(plugin = "maven-publish") + apply(plugin = "signing") + + tasks { + val dokkaOutputDir = "$buildDir/dokka" + + dokkaHtml { + outputDirectory.set(file(dokkaOutputDir)) + } + } + + publishing { + // Configure all publications + publications.withType { + val publication = this + val dokkaJar = tasks.register("${publication.name}DokkaJar") { + group = JavaBasePlugin.DOCUMENTATION_GROUP + description = "Assembles Kotlin docs with Dokka into a Javadoc jar" + archiveClassifier.set("javadoc") + from(tasks.named("dokkaHtml")) + // Each archive name should be distinct, to avoid implicit dependency issues. + // We use the same format as the sources Jar tasks. + // https://youtrack.jetbrains.com/issue/KT-46466 + archiveBaseName.set("${archiveBaseName.get()}-${publication.name}") + } + + artifact(dokkaJar) + + // Provide artifacts information required by Maven Central + pom { + url.set("https://github.com/voize-gmbh/typescriptpoet") + + licenses { + license { + name.set("Apache-2.0") + url.set("https://opensource.org/licenses/Apache-2.0") + } + } + developers { + developer { + id.set("LeonKiefer") + name.set("Leon Kiefer") + email.set("leon@voize.de") + } + developer { + id.set("ErikZiegler") + name.set("Erik Ziegler") + email.set("erik@voize.de") + } + } + scm { + url.set("https://github.com/voize-gmbh/typescriptpoet") + } + } + } + } + + if (signingPassword != null) { + signing { + if (signingKey != null) { + useInMemoryPgpKeys(signingKey, signingPassword) + } + sign(publishing.publications) + } + } +} +