diff --git a/build.gradle.kts b/build.gradle.kts index b626384..54f4375 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,47 +1,64 @@ +@file:OptIn(ExperimentalKotlinGradlePluginApi::class) + import io.github.petertrr.configurePublishing +import io.github.petertrr.ext.booleanProperty import io.gitlab.arturbosch.detekt.Detekt -import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion plugins { kotlin("multiplatform") - id("jacoco-convention") alias(libs.plugins.detekt) + id("jacoco-convention") } group = "io.github.petertrr" description = "A multiplatform Kotlin library for calculating text differences" +dependencies { + detektPlugins(libs.detekt.formatting) +} + kotlin { explicitApi() - jvm() - js(IR) { + compilerOptions { + apiVersion = KotlinVersion.KOTLIN_1_9 + languageVersion = KotlinVersion.KOTLIN_1_9 + } + + jvm { + compilations.configureEach { + compilerOptions.configure { + // Minimum bytecode level is 52 + jvmTarget = JvmTarget.JVM_1_8 + + // Output interfaces with default methods + freeCompilerArgs.add("-Xjvm-default=all") + } + } + + testRuns.configureEach { + executionTask.configure { + useJUnitPlatform() + } + } + } + + js { browser() nodejs() } - // setup native compilation + linuxX64() mingwX64() macosX64() sourceSets { - val commonTest by getting { - dependencies { - implementation(kotlin("test-common")) - implementation(kotlin("test-annotations-common")) - } - } - // platform-specific dependencies are needed to use actual test runners - val jvmTest by getting { - dependencies { - implementation(kotlin("test-junit5")) - implementation(libs.junit.jupiter.engine) - runtimeOnly("org.junit.platform:junit-platform-launcher") - } - } - val jsTest by getting { + commonTest { dependencies { - implementation(kotlin("test-js")) + implementation(kotlin("test")) } } } @@ -49,18 +66,16 @@ kotlin { configurePublishing() -tasks.withType { - useJUnitPlatform() -} - detekt { buildUponDefaultConfig = true config.setFrom(files("detekt.yml")) - autoCorrect = (findProperty("detektAutoCorrect") as String?)?.toBoolean() ?: true -} -dependencies { - detektPlugins(libs.detekt.formatting) + autoCorrect = booleanProperty("detektAutoCorrect", default = true) } -tasks.withType { - tasks.getByName("check").dependsOn(this) + +tasks { + withType { + named("check") { + dependsOn(this@withType) + } + } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 3cfa691..7b59200 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -2,14 +2,8 @@ plugins { `kotlin-dsl` } -repositories { - mavenCentral() - gradlePluginPortal() -} - -val libs = extensions.getByType().named("libs") dependencies { - implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.9.10") - implementation("io.github.gradle-nexus:publish-plugin:1.3.0") - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.findVersion("kotlin").get()}") -} \ No newline at end of file + implementation(libs.dokka.plugin) + implementation(libs.nexus.plugin) + implementation(libs.kotlin.plugin) +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index b5a0fab..b55500c 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -1,4 +1,10 @@ dependencyResolutionManagement { + @Suppress("UnstableApiUsage") + repositories { + mavenCentral() + gradlePluginPortal() + } + versionCatalogs { create("libs") { from(files("../gradle/libs.versions.toml")) diff --git a/buildSrc/src/main/kotlin/io/github/petertrr/ext/Project.ext.kt b/buildSrc/src/main/kotlin/io/github/petertrr/ext/Project.ext.kt new file mode 100644 index 0000000..3ef99ae --- /dev/null +++ b/buildSrc/src/main/kotlin/io/github/petertrr/ext/Project.ext.kt @@ -0,0 +1,12 @@ +package io.github.petertrr.ext + +import org.gradle.api.Project + +/** + * Returns a project property as a boolean (`"true" == true`, else `false`). + */ +fun Project.booleanProperty(name: String, default: Boolean = false): Boolean { + val property = findProperty(name) ?: return default + val propertyStr = property as? String ?: return default + return propertyStr.trim().lowercase() == "true" +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d42f667..16b9c3e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,13 +1,16 @@ [versions] -kotlin = "1.9.22" -junit = "5.10.1" +kotlin = "1.9.23" detekt = "1.23.5" +dokka = "1.9.10" +nexus = "1.3.0" [plugins] -kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } [libraries] -junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" } -junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" } -detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } +detekt-formatting = { group = "io.gitlab.arturbosch.detekt", name = "detekt-formatting", version.ref = "detekt" } + +# Gradle plugins +kotlin-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" } +dokka-plugin = { group = "org.jetbrains.dokka", name = "dokka-gradle-plugin", version.ref = "dokka" } +nexus-plugin = { group = "io.github.gradle-nexus", name = "publish-plugin", version.ref = "nexus" } diff --git a/settings.gradle.kts b/settings.gradle.kts index e0403db..0d41076 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -13,6 +13,7 @@ plugins { rootProject.name = "kotlin-multiplatform-diff" dependencyResolutionManagement { + @Suppress("UnstableApiUsage") repositories { mavenCentral() }