From 5869b9aa16b45a236c6da8d60028b24225d96447 Mon Sep 17 00:00:00 2001 From: Michael Rittmeister Date: Mon, 4 Mar 2024 21:51:53 +0100 Subject: [PATCH] Suggestions - Remove blank lines in common/build.gradle.kts - Replace kord-internal-multiplatform-module.gradle.kts and kord-native-module.gradle.kts with kord-targets.gradle.kts - Check for target family rather than explicit target in samples/build.gradle.kts - Add slf4j dependency to voice - Remove nonNative target group - Use HostManager.hostIsMingw instead of Ant's Os class - Move nativeMain builder and jsMain to nonJvmMain - Add versions of remaining Gradle plugins to [versions] block - No longer catch exception in native test kit --- ...d-internal-multiplatform-module.gradle.kts | 26 --------- .../src/main/kotlin/kord-module.gradle.kts | 58 ------------------- .../kord-multiplatform-module.gradle.kts | 14 ----- ...ule.gradle.kts => kord-targets.gradle.kts} | 10 +++- common/build.gradle.kts | 6 +- core-voice/build.gradle.kts | 2 +- core/build.gradle.kts | 2 +- core/live-tests/build.gradle.kts | 2 +- core/src/nativeMain/kotlin/KordBuilder.kt | 3 - .../kotlin/KordBuilder.kt | 0 gateway/build.gradle.kts | 2 +- gradle/libs.versions.toml | 7 ++- ksp-annotations/build.gradle.kts | 3 +- rest/build.gradle.kts | 2 +- samples/build.gradle.kts | 8 +-- test-kit/build.gradle.kts | 3 +- test-kit/src/nativeMain/kotlin/Platform.kt | 8 +-- voice/build.gradle.kts | 7 ++- 18 files changed, 31 insertions(+), 132 deletions(-) delete mode 100644 buildSrc/src/main/kotlin/kord-internal-multiplatform-module.gradle.kts delete mode 100644 buildSrc/src/main/kotlin/kord-module.gradle.kts rename buildSrc/src/main/kotlin/{kord-native-module.gradle.kts => kord-targets.gradle.kts} (74%) delete mode 100644 core/src/nativeMain/kotlin/KordBuilder.kt rename core/src/{jsMain => nonJvmMain}/kotlin/KordBuilder.kt (100%) diff --git a/buildSrc/src/main/kotlin/kord-internal-multiplatform-module.gradle.kts b/buildSrc/src/main/kotlin/kord-internal-multiplatform-module.gradle.kts deleted file mode 100644 index a5624e16aba..00000000000 --- a/buildSrc/src/main/kotlin/kord-internal-multiplatform-module.gradle.kts +++ /dev/null @@ -1,26 +0,0 @@ -import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi - -plugins { - org.jetbrains.kotlin.multiplatform -} - -repositories { - mavenCentral() -} - -@OptIn(ExperimentalKotlinGradlePluginApi::class) -kotlin { - applyDefaultHierarchyTemplate() - jvm() - js { - nodejs() - useCommonJs() - } - jvmToolchain(Jvm.target) - - targets.all { - compilations.all { - compilerOptions.options.applyKordCompilerOptions() - } - } -} diff --git a/buildSrc/src/main/kotlin/kord-module.gradle.kts b/buildSrc/src/main/kotlin/kord-module.gradle.kts deleted file mode 100644 index c373ec3279f..00000000000 --- a/buildSrc/src/main/kotlin/kord-module.gradle.kts +++ /dev/null @@ -1,58 +0,0 @@ -import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask - -plugins { - org.jetbrains.kotlin.jvm - org.jetbrains.kotlin.plugin.serialization - org.jetbrains.dokka - `kotlinx-atomicfu` - org.jetbrains.kotlinx.`binary-compatibility-validator` - com.google.devtools.ksp - `maven-publish` -} - -repositories { - mavenCentral() -} - -dependencies { - ksp(project(":ksp-processors")) -} - -apiValidation { - applyKordBCVOptions() -} - -kotlin { - explicitApi() - - jvmToolchain(Jvm.target) - - compilerOptions { - applyKordCompilerOptions() - optIn.addAll(kordOptIns) - } - - sourceSets { - // allow `ExperimentalCoroutinesApi` for `TestScope.currentTime` - test { languageSettings.optIn(OptIns.coroutines) } - } -} - -configureAtomicFU() - -tasks { - withType().configureEach { - useJUnitPlatform() - } - - withType().configureEach { - applyKordDokkaOptions() - } -} - -publishing { - publications.register(Library.name) { - from(components["java"]) - artifact(tasks.kotlinSourcesJar) - } -} diff --git a/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts b/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts index d5afd7918b6..d34b122835e 100644 --- a/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts @@ -33,24 +33,10 @@ kotlin { withNative() withJs() } - - group("nonNative") { - withJs() - withJvm() - } } } explicitApi() - - jvm() - - if (name != "voice" && name != "core-voice") { - js { - nodejs() - useCommonJs() - } - } jvmToolchain(Jvm.target) targets.all { diff --git a/buildSrc/src/main/kotlin/kord-native-module.gradle.kts b/buildSrc/src/main/kotlin/kord-targets.gradle.kts similarity index 74% rename from buildSrc/src/main/kotlin/kord-native-module.gradle.kts rename to buildSrc/src/main/kotlin/kord-targets.gradle.kts index a6e5a849285..63125e6daf7 100644 --- a/buildSrc/src/main/kotlin/kord-native-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-targets.gradle.kts @@ -1,4 +1,4 @@ -import org.apache.tools.ant.taskdefs.condition.Os +import org.jetbrains.kotlin.konan.target.HostManager plugins { org.jetbrains.kotlin.multiplatform @@ -7,13 +7,19 @@ plugins { kotlin { // There are issues with compiling the linux variant on windows // Please use WSL if you need to work on the linux port - if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + if (!HostManager.hostIsMingw) { linuxX64() linuxArm64() } + jvm() + if (name != "voice" && name != "core-voice") { mingwX64() + js { + nodejs() + useCommonJs() + } } macosArm64() diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 1c4c3473a02..927677dde73 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -2,7 +2,7 @@ import dev.kord.gradle.tools.util.commitHash import dev.kord.gradle.tools.util.shortCommitHash plugins { - `kord-native-module` + `kord-targets` `kord-multiplatform-module` `kord-publishing` alias(libs.plugins.buildconfig) @@ -41,26 +41,22 @@ kotlin { implementation(projects.kspAnnotations) } } - nativeMain { dependencies { // Native does not have compileOnly implementation(projects.kspAnnotations) } } - mingwMain { dependencies { api(libs.ktor.client.winhttp) } } - appleMain { dependencies { api(libs.ktor.client.darwin) } } - linuxMain { dependencies { api(libs.ktor.client.curl) diff --git a/core-voice/build.gradle.kts b/core-voice/build.gradle.kts index 412df014aa5..d8efe0d18a8 100644 --- a/core-voice/build.gradle.kts +++ b/core-voice/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - `kord-native-module` + `kord-targets` `kord-multiplatform-module` `kord-publishing` } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index d0059c9c312..c326190d659 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - `kord-native-module` + `kord-targets` `kord-multiplatform-module` `kord-publishing` } diff --git a/core/live-tests/build.gradle.kts b/core/live-tests/build.gradle.kts index 86fe49a30fc..ea3b8e3de70 100644 --- a/core/live-tests/build.gradle.kts +++ b/core/live-tests/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - `kord-internal-multiplatform-module` + `kord-targets` } kotlin { diff --git a/core/src/nativeMain/kotlin/KordBuilder.kt b/core/src/nativeMain/kotlin/KordBuilder.kt deleted file mode 100644 index a3d196befb4..00000000000 --- a/core/src/nativeMain/kotlin/KordBuilder.kt +++ /dev/null @@ -1,3 +0,0 @@ -package dev.kord.core.builder.kord - -public actual class KordBuilder actual constructor(token: String) : BaseKordBuilder(token) diff --git a/core/src/jsMain/kotlin/KordBuilder.kt b/core/src/nonJvmMain/kotlin/KordBuilder.kt similarity index 100% rename from core/src/jsMain/kotlin/KordBuilder.kt rename to core/src/nonJvmMain/kotlin/KordBuilder.kt diff --git a/gateway/build.gradle.kts b/gateway/build.gradle.kts index 4d910dce089..6e3372b6f27 100644 --- a/gateway/build.gradle.kts +++ b/gateway/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - `kord-native-module` + `kord-targets` `kord-multiplatform-module` `kord-publishing` } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 61983d8f10d..b15b7247abb 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -31,7 +31,8 @@ dokka = "1.9.20" # https://github.com/Kotlin/dokka kotlinx-atomicfu = "0.23.2" # https://github.com/Kotlin/kotlinx-atomicfu binary-compatibility-validator = "0.14.0" # https://github.com/Kotlin/binary-compatibility-validator buildconfig = "5.3.5" # https://github.com/gmazzo/gradle-buildconfig-plugin - +kord-gradle-tools = "1.3.0" # https://github.com/kordlib/gradle-tools +maven-publish-plugin = "0.27.0" # https://github.com/vanniktech/gradle-maven-publish-plugin [libraries] @@ -92,8 +93,8 @@ dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref atomicfu-plugin = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "kotlinx-atomicfu" } binary-compatibility-validator-plugin = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "binary-compatibility-validator" } ksp-plugin = { module = "com.google.devtools.ksp:symbol-processing-gradle-plugin", version.ref = "ksp" } -kord-gradle-plugin = { module = "dev.kord:gradle-tools", version = "1.3.0" } -maven-publish-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.27.0" } +kord-gradle-plugin = { module = "dev.kord:gradle-tools", version.ref = "kord-gradle-tools" } +maven-publish-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "maven-publish-plugin" } [bundles] diff --git a/ksp-annotations/build.gradle.kts b/ksp-annotations/build.gradle.kts index 74548672acb..4d38af49489 100644 --- a/ksp-annotations/build.gradle.kts +++ b/ksp-annotations/build.gradle.kts @@ -1,8 +1,7 @@ import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask plugins { - `kord-native-module` - `kord-internal-multiplatform-module` + `kord-targets` // workaround for https://youtrack.jetbrains.com/issue/KT-43500 (not intended to be published) org.jetbrains.dokka diff --git a/rest/build.gradle.kts b/rest/build.gradle.kts index 6ccbec4d98a..7db0c64b3ef 100644 --- a/rest/build.gradle.kts +++ b/rest/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - `kord-native-module` + `kord-targets` `kord-multiplatform-module` `kord-publishing` } diff --git a/samples/build.gradle.kts b/samples/build.gradle.kts index cf0112239c1..84b8ef3b862 100644 --- a/samples/build.gradle.kts +++ b/samples/build.gradle.kts @@ -1,10 +1,9 @@ import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.konan.target.KonanTarget +import org.jetbrains.kotlin.konan.target.Family plugins { - `kord-internal-multiplatform-module` - `kord-native-module` + `kord-targets` } @OptIn(ExperimentalKotlinGradlePluginApi::class) @@ -23,7 +22,8 @@ kotlin { } targets.withType { - if (konanTarget != KonanTarget.MINGW_X64) { + // Voice does not target windows, so we disable it + if (konanTarget.family != Family.MINGW) { binaries.executable { entryPoint = "dev.kord.voice.test.main" } diff --git a/test-kit/build.gradle.kts b/test-kit/build.gradle.kts index ef1e6491205..4c25f2582ee 100644 --- a/test-kit/build.gradle.kts +++ b/test-kit/build.gradle.kts @@ -1,8 +1,7 @@ import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi plugins { - `kord-native-module` - `kord-internal-multiplatform-module` + `kord-targets` } @OptIn(ExperimentalKotlinGradlePluginApi::class) diff --git a/test-kit/src/nativeMain/kotlin/Platform.kt b/test-kit/src/nativeMain/kotlin/Platform.kt index eb4e9e8a879..01887908a3e 100644 --- a/test-kit/src/nativeMain/kotlin/Platform.kt +++ b/test-kit/src/nativeMain/kotlin/Platform.kt @@ -33,11 +33,5 @@ actual suspend fun readFile(project: String, path: String): ByteReadChannel = private inline fun read(project: String, path: String, readerAction: Source.() -> T): T { val actualPath = Path("${getEnv("PROJECT_ROOT")}/$project/src/commonTest/resources/$path") - return try { - SystemFileSystem.source(actualPath).buffered().readerAction() - } catch (e: Throwable) { - throw FileNotFoundException(actualPath.toString(), e) - } + return SystemFileSystem.source(actualPath).buffered().readerAction() } - -class FileNotFoundException(absolutePath: String, cause: Throwable) : IOException("Absolute Path: $absolutePath", cause) diff --git a/voice/build.gradle.kts b/voice/build.gradle.kts index 326c5bae85d..86ba3458131 100644 --- a/voice/build.gradle.kts +++ b/voice/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - `kord-native-module` + `kord-targets` `kord-multiplatform-module` `kord-publishing` } @@ -27,5 +27,10 @@ kotlin { implementation(libs.libsodium) } } + jvmMain { + dependencies { + implementation(libs.slf4j.api) + } + } } }