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 diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..64bc195 --- /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" +} + +val toPublish = listOf("core") + +subprojects { + if (name in toPublish) { + 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..44cf02a --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,15 @@ +repositories { + google() + mavenCentral() +} + +plugins { + alias(libs.plugins.kotlinJvm) + `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..dccaec4 --- /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 signingInMemoryKeyId: String? by project + val signingInMemoryKey: String? by project + val signingInMemoryKeyPassword: String? by project + + val canSign = signingInMemoryKeyId != null && signingInMemoryKey != null + val isSnapshot = (version as String).endsWith("-SNAPSHOT") + val canPublish = mavenCentralUsername != null && mavenCentralPassword != null && (canSign || isSnapshot) + + if (canPublish) { + configure { + isRequired = !isSnapshot + useInMemoryPgpKeys(signingInMemoryKeyId, signingInMemoryKeyId, signingInMemoryKeyPassword ?: "") + } + + configure { + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = false) + 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..c3ecc6e 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,32 +1,28 @@ 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 +31,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/settings.gradle.kts b/settings.gradle.kts index e5cb689..4118ec0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,9 @@ -plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" +dependencyResolutionManagement { + repositories { + mavenCentral() + } } -rootProject.name = "JDUI" -include("core") -include("example") +rootProject.name = "jdui" + +include("core", "example")