From 05f326ea9353160223b15cee1361400514790d31 Mon Sep 17 00:00:00 2001 From: Marcel Korzonek Date: Wed, 14 May 2025 15:19:18 +0200 Subject: [PATCH 1/6] Add maven central publishing logic --- build.gradle.kts | 18 +++++ buildSrc/build.gradle.kts | 15 ++++ buildSrc/settings.gradle.kts | 7 ++ .../main/kotlin/dev/xirado/jdui/Publishing.kt | 66 ++++++++++++++++ core/build.gradle.kts | 76 ++++--------------- example/build.gradle.kts | 11 +-- gradle/libs.versions.toml | 31 ++++++++ gradle/publish.gradle.kts | 62 +++++++++++++++ settings.gradle.kts | 21 +++-- 9 files changed, 232 insertions(+), 75 deletions(-) create mode 100644 build.gradle.kts create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/settings.gradle.kts create mode 100644 buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt create mode 100644 gradle/libs.versions.toml create mode 100644 gradle/publish.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..8a3b002 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,18 @@ +import dev.xirado.jdui.configurePublishing + +plugins { + kotlin("jvm") apply true +} + +allprojects { + group = "dev.xirado" + version = "0.1.0-SNAPSHOT" +} + +subprojects { + afterEvaluate { + if (name != "example") { + configurePublishing() + } + } +} \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..3ebe56c --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,15 @@ +repositories { + google() + mavenCentral() +} + +plugins { + kotlin("jvm") version "2.1.0" // 👈 use the correct version + `kotlin-dsl` apply true +} + +dependencies { + gradleApi() + implementation(libs.jvm) + implementation(libs.publishing) +} \ No newline at end of file diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 0000000..fa8bc74 --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,7 @@ +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt b/buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt new file mode 100644 index 0000000..7677736 --- /dev/null +++ b/buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt @@ -0,0 +1,66 @@ +package dev.xirado.jdui + +import com.vanniktech.maven.publish.MavenPublishBaseExtension +import com.vanniktech.maven.publish.SonatypeHost +import org.gradle.api.Project +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.assign +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.provideDelegate +import org.gradle.plugins.signing.SigningExtension + +fun Project.configurePublishing() { + apply(plugin = "signing") + apply(plugin = "com.vanniktech.maven.publish") + + val mavenCentralUsername: String? by project + val mavenCentralPassword: String? by project + + val pgpKeyId: String? by project + val pgpSecretKey: String? by project + + val canSign = pgpKeyId != null && pgpSecretKey != null + val isSnapshot = (version as String).endsWith("-SNAPSHOT") + val canPublish = mavenCentralUsername != null && mavenCentralPassword != null && (canSign || isSnapshot) + + if (canPublish) { + println("Configuring maven publishing ${project.name}") + configure { + isRequired = !isSnapshot + useInMemoryPgpKeys(pgpKeyId, pgpSecretKey, "") + } + + configure { + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true) + signAllPublications() + coordinates("dev.xirado", "jdui-${project.name}", project.version as String) + + pom { + description = "Kotlin library for effortlessly creating stateful and interactive messages in Discord with 0 boilerplate" + url = "https://github.com/Xirado/JDUI" + + licenses { + license { + name = "Apache License, Version 2.0" + url = "https://opensource.org/license/apache-2-0" + distribution = "repo" + } + } + + developers { + developer { + id.set("Xirado") + name.set("Marcel Korzonek") + email.set("marcel@xirado.dev") + } + } + + scm { + connection = "scm:git:https://github.com/Xirado/JDUI.git" + developerConnection = "scm:git:https://github.com/Xirado/JDUI.git" + url = "https://github.com/Xirado/JDUI" + } + } + } + } +} \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 0844e45..6cd4d7b 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,32 +1,29 @@ + plugins { - kotlin("jvm") version "2.0.20" - kotlin("plugin.serialization") version "2.0.20" - `maven-publish` + kotlin("jvm") + alias(libs.plugins.kotlinSerialization) } -group = "at.xirado" -version = "0.1.0" - repositories { mavenCentral() maven("https://jitpack.io") } dependencies { - compileOnly("io.github.freya022:JDA:54038f1cec") + compileOnly(libs.jda) - api("org.slf4j:slf4j-api:2.0.13") - api("io.github.oshai:kotlin-logging-jvm:5.1.0") + api(libs.slf4j) + api(libs.kotlin.logging) - api("de.mkammerer.snowflake-id:snowflake-id:0.0.2") - api("com.github.ben-manes.caffeine:caffeine:3.1.8") + api(libs.snowflake) + api(libs.caffeine) - api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1") - api("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.8.1") - api("org.jetbrains.kotlin:kotlin-reflect:2.0.20") + api(libs.kotlin.coroutines) + api(libs.kotlin.protobuf) + api(libs.kotlin.reflect) - testImplementation(kotlin("test")) - testImplementation("io.github.freya022:JDA:4b468cdd09") + testImplementation(libs.kotlin.test) + testImplementation(libs.jda) } tasks.test { @@ -35,51 +32,4 @@ tasks.test { kotlin { jvmToolchain(17) -} - -val javadoc: Javadoc by tasks - -val sourcesJar = task("sourcesJar") { - from(sourceSets["main"].allSource) - archiveClassifier.set("sources") -} - -val javadocJar = task("javadocJar") { - from(javadoc.destinationDir) - archiveClassifier.set("javadoc") - - dependsOn(javadoc) -} - -tasks { - build { - dependsOn(javadocJar) - dependsOn(sourcesJar) - dependsOn(jar) - } -} - -publishing { - repositories { - maven { - name = "repoReleases" - url = uri("https://maven.xirado.dev/releases") - credentials(PasswordCredentials::class) - authentication { - create("basic") - } - } - } - - publications { - register("release") { - from(components["java"]) - groupId = "at.xirado" - artifactId = "JDUI" - version = project.version as String - - artifact(javadocJar) - artifact(sourcesJar) - } - } } \ No newline at end of file diff --git a/example/build.gradle.kts b/example/build.gradle.kts index 3eff82a..f6b88af 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -1,12 +1,9 @@ plugins { - kotlin("jvm") version "2.0.20" - kotlin("plugin.serialization") version "2.0.20" + kotlin("jvm") + alias(libs.plugins.kotlinSerialization) application } -group = "at.xirado" -version = "0.1.0" - application { mainClass.set("at.xirado.jdui.example.MainKt") } @@ -19,7 +16,7 @@ repositories { dependencies { implementation(project(":core")) - implementation("io.github.freya022:JDA:54038f1cec") + implementation(libs.jda) implementation("club.minnced:jda-ktx:0.12.0") implementation("ch.qos.logback:logback-classic:1.5.6") @@ -27,7 +24,7 @@ dependencies { implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0") - testImplementation(kotlin("test")) + testImplementation(libs.kotlin.test) } tasks.test { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..10a8dbd --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,31 @@ +[versions] +kotlin = "2.1.0" +publishing = "0.31.0" + +kotlin-coroutines = "1.10.1" +kotlin-protobuf = "1.8.1" + +jda = "54038f1cec" +slf4j-api = "2.0.13" +kotlin-logging = "5.1.0" +snowflake-id = "0.0.2" +caffeine = "3.1.8" + +[libraries] +jvm = { group = "org.jetbrains.kotlin.jvm", name = "org.jetbrains.kotlin.jvm.gradle.plugin", version.ref = "kotlin" } +kotlin-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm", version.ref = "kotlin-coroutines" } +kotlin-protobuf = { module = "org.jetbrains.kotlinx:kotlinx-serialization-protobuf", version.ref = "kotlin-protobuf" } +kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" } +kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } +kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } + +jda = { module = "io.github.freya022:JDA", version.ref = "jda" } +slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j-api" } +kotlin-logging = { module = "io.github.oshai:kotlin-logging-jvm", version.ref = "kotlin-logging" } +snowflake = { module = "de.mkammerer.snowflake-id:snowflake-id", version.ref = "snowflake-id" } +caffeine = { module = "com.github.ben-manes.caffeine:caffeine", version.ref = "caffeine" } +publishing = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "publishing" } + +[plugins] +kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } diff --git a/gradle/publish.gradle.kts b/gradle/publish.gradle.kts new file mode 100644 index 0000000..61ea7ad --- /dev/null +++ b/gradle/publish.gradle.kts @@ -0,0 +1,62 @@ +//import com.vanniktech.maven.publish.MavenPublishBaseExtension +//plugins { +// id("com.vanniktech.maven.publish") +// signing +//} + + +apply(plugin = "com.vanniktech.maven.publish") +apply(plugin = "signing") + +buildscript { + val mavenCentralUsername: String? by project + val mavenCentralPassword: String? by project + + val pgpKeyId: String? by project + val pgpSecretKey: String? by project + + val canSign = pgpKeyId != null && pgpSecretKey != null + val isSnapshot = (version as String).endsWith("-SNAPSHOT") + val canPublish = mavenCentralUsername != null && mavenCentralPassword != null && (canSign || isSnapshot) + + + + if (canPublish) { + configure { + isRequired = !isSnapshot + useInMemoryPgpKeys(pgpKeyId, pgpSecretKey, "") + } + + configure { + signAllPublications() + coordinates("dev.xirado", "jdui-${project.name}", project.version as String) + + pom { + description = "Kotlin library for effortlessly creating stateful and interactive messages in Discord with 0 boilerplate" + url = "https://github.com/Xirado/JDUI" + + licenses { + license { + name = "Apache License, Version 2.0" + url = "https://opensource.org/license/apache-2-0" + distribution = "repo" + } + } + + developers { + developer { + id.set("Xirado") + name.set("Marcel Korzonek") + email.set("marcel@xirado.dev") + } + } + + scm { + connection = "scm:git:https://github.com/Xirado/JDUI.git" + developerConnection = "scm:git:https://github.com/Xirado/JDUI.git" + url = "https://github.com/Xirado/JDUI" + } + } + } + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index e5cb689..4613c88 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,18 @@ -plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" +pluginManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } } -rootProject.name = "JDUI" -include("core") -include("example") +dependencyResolutionManagement { + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "jdui" + +include("core", "example") From 713980daa15bf0a3f23c0fd8a94819788f20a77a Mon Sep 17 00:00:00 2001 From: Marcel Korzonek Date: Fri, 16 May 2025 13:55:14 +0200 Subject: [PATCH 2/6] Fix signing --- build.gradle.kts | 8 ++++---- buildSrc/build.gradle.kts | 2 +- buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt | 10 +++++----- core/build.gradle.kts | 1 - 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8a3b002..64bc195 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,10 +9,10 @@ allprojects { version = "0.1.0-SNAPSHOT" } +val toPublish = listOf("core") + subprojects { - afterEvaluate { - if (name != "example") { - configurePublishing() - } + if (name in toPublish) { + configurePublishing() } } \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 3ebe56c..44cf02a 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -4,7 +4,7 @@ repositories { } plugins { - kotlin("jvm") version "2.1.0" // 👈 use the correct version + alias(libs.plugins.kotlinJvm) `kotlin-dsl` apply true } diff --git a/buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt b/buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt index 7677736..086d0b6 100644 --- a/buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt +++ b/buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt @@ -16,18 +16,18 @@ fun Project.configurePublishing() { val mavenCentralUsername: String? by project val mavenCentralPassword: String? by project - val pgpKeyId: String? by project - val pgpSecretKey: String? by project + val signingInMemoryKeyId: String? by project + val signingInMemoryKey: String? by project + val signingInMemoryKeyPassword: String? by project - val canSign = pgpKeyId != null && pgpSecretKey != null + val canSign = signingInMemoryKeyId != null && signingInMemoryKey != null val isSnapshot = (version as String).endsWith("-SNAPSHOT") val canPublish = mavenCentralUsername != null && mavenCentralPassword != null && (canSign || isSnapshot) if (canPublish) { - println("Configuring maven publishing ${project.name}") configure { isRequired = !isSnapshot - useInMemoryPgpKeys(pgpKeyId, pgpSecretKey, "") + useInMemoryPgpKeys(signingInMemoryKeyId, signingInMemoryKeyId, signingInMemoryKeyPassword ?: "") } configure { diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 6cd4d7b..c3ecc6e 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,4 +1,3 @@ - plugins { kotlin("jvm") alias(libs.plugins.kotlinSerialization) From 01d1e9888bc946878339f9367a6d27991efb766f Mon Sep 17 00:00:00 2001 From: Marcel Korzonek Date: Fri, 16 May 2025 14:00:07 +0200 Subject: [PATCH 3/6] Disable automatic staging repo release --- buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt b/buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt index 086d0b6..dccaec4 100644 --- a/buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt +++ b/buildSrc/src/main/kotlin/dev/xirado/jdui/Publishing.kt @@ -31,7 +31,7 @@ fun Project.configurePublishing() { } configure { - publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true) + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = false) signAllPublications() coordinates("dev.xirado", "jdui-${project.name}", project.version as String) From dd8558bb30a9550c1fef7322557e3131efba3358 Mon Sep 17 00:00:00 2001 From: Marcel Korzonek Date: Fri, 16 May 2025 20:05:33 +0200 Subject: [PATCH 4/6] Add github workflow for publishing --- .github/workflows/publish.yml | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..67f5e55 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,37 @@ +name: Publish to Maven Central + +on: + workflow_dispatch: + +concurrency: + group: "publish" + +jobs: + publish: + environment: maven-release + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + - name: Release to Maven Central + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.MAVEN_CENTRAL_PGP_KEY_ID }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MAVEN_CENTRAL_PGP_SECRET_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.MAVEN_CENTRAL_PGP_SECRET_PASSWORD }} + run: ./gradlew clean build publishToMavenCentral + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: Artifacts + path: | + build/libs/*.jar + build/libs/*.jar.asc \ No newline at end of file From 6992922af9c33ae7cf41026eac8edcf9a6d7a567 Mon Sep 17 00:00:00 2001 From: Marcel Korzonek Date: Fri, 16 May 2025 20:08:28 +0200 Subject: [PATCH 5/6] Remove publish.gradle.kts --- gradle/publish.gradle.kts | 62 --------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 gradle/publish.gradle.kts diff --git a/gradle/publish.gradle.kts b/gradle/publish.gradle.kts deleted file mode 100644 index 61ea7ad..0000000 --- a/gradle/publish.gradle.kts +++ /dev/null @@ -1,62 +0,0 @@ -//import com.vanniktech.maven.publish.MavenPublishBaseExtension -//plugins { -// id("com.vanniktech.maven.publish") -// signing -//} - - -apply(plugin = "com.vanniktech.maven.publish") -apply(plugin = "signing") - -buildscript { - val mavenCentralUsername: String? by project - val mavenCentralPassword: String? by project - - val pgpKeyId: String? by project - val pgpSecretKey: String? by project - - val canSign = pgpKeyId != null && pgpSecretKey != null - val isSnapshot = (version as String).endsWith("-SNAPSHOT") - val canPublish = mavenCentralUsername != null && mavenCentralPassword != null && (canSign || isSnapshot) - - - - if (canPublish) { - configure { - isRequired = !isSnapshot - useInMemoryPgpKeys(pgpKeyId, pgpSecretKey, "") - } - - configure { - signAllPublications() - coordinates("dev.xirado", "jdui-${project.name}", project.version as String) - - pom { - description = "Kotlin library for effortlessly creating stateful and interactive messages in Discord with 0 boilerplate" - url = "https://github.com/Xirado/JDUI" - - licenses { - license { - name = "Apache License, Version 2.0" - url = "https://opensource.org/license/apache-2-0" - distribution = "repo" - } - } - - developers { - developer { - id.set("Xirado") - name.set("Marcel Korzonek") - email.set("marcel@xirado.dev") - } - } - - scm { - connection = "scm:git:https://github.com/Xirado/JDUI.git" - developerConnection = "scm:git:https://github.com/Xirado/JDUI.git" - url = "https://github.com/Xirado/JDUI" - } - } - } - } -} \ No newline at end of file From dedcd2590568fab8cd50daf3cf1f0ab47e56bef8 Mon Sep 17 00:00:00 2001 From: Marcel Korzonek Date: Fri, 16 May 2025 20:13:17 +0200 Subject: [PATCH 6/6] Remove pluginManagement() in root settings.gradle.kts --- settings.gradle.kts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 4613c88..4118ec0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,14 +1,5 @@ -pluginManagement { - repositories { - google() - gradlePluginPortal() - mavenCentral() - } -} - dependencyResolutionManagement { repositories { - google() mavenCentral() } }