-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update build configuration to reflect KGP improvements (#102)
I did a bit of a cleanup of the build scripts. Removed what wasn't necessary, centralized all dependencies in the root version catalog, and applied a more specific configuration to the JVM target.
- Loading branch information
Showing
6 changed files
with
78 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,81 @@ | ||
@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")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
configurePublishing() | ||
|
||
tasks.withType<KotlinJvmTest> { | ||
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<Detekt> { | ||
tasks.getByName("check").dependsOn(this) | ||
|
||
tasks { | ||
withType<Detekt> { | ||
named("check") { | ||
dependsOn(this@withType) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
buildSrc/src/main/kotlin/io/github/petertrr/ext/Project.ext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters