Skip to content

Commit b370f69

Browse files
authored
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.
1 parent 2d978a9 commit b370f69

File tree

6 files changed

+78
-47
lines changed

6 files changed

+78
-47
lines changed

Diff for: build.gradle.kts

+46-31
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,81 @@
1+
@file:OptIn(ExperimentalKotlinGradlePluginApi::class)
2+
13
import io.github.petertrr.configurePublishing
4+
import io.github.petertrr.ext.booleanProperty
25
import io.gitlab.arturbosch.detekt.Detekt
3-
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
6+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
7+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
8+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
49

510
plugins {
611
kotlin("multiplatform")
7-
id("jacoco-convention")
812
alias(libs.plugins.detekt)
13+
id("jacoco-convention")
914
}
1015

1116
group = "io.github.petertrr"
1217
description = "A multiplatform Kotlin library for calculating text differences"
1318

19+
dependencies {
20+
detektPlugins(libs.detekt.formatting)
21+
}
22+
1423
kotlin {
1524
explicitApi()
1625

17-
jvm()
18-
js(IR) {
26+
compilerOptions {
27+
apiVersion = KotlinVersion.KOTLIN_1_9
28+
languageVersion = KotlinVersion.KOTLIN_1_9
29+
}
30+
31+
jvm {
32+
compilations.configureEach {
33+
compilerOptions.configure {
34+
// Minimum bytecode level is 52
35+
jvmTarget = JvmTarget.JVM_1_8
36+
37+
// Output interfaces with default methods
38+
freeCompilerArgs.add("-Xjvm-default=all")
39+
}
40+
}
41+
42+
testRuns.configureEach {
43+
executionTask.configure {
44+
useJUnitPlatform()
45+
}
46+
}
47+
}
48+
49+
js {
1950
browser()
2051
nodejs()
2152
}
22-
// setup native compilation
53+
2354
linuxX64()
2455
mingwX64()
2556
macosX64()
2657

2758
sourceSets {
28-
val commonTest by getting {
29-
dependencies {
30-
implementation(kotlin("test-common"))
31-
implementation(kotlin("test-annotations-common"))
32-
}
33-
}
34-
// platform-specific dependencies are needed to use actual test runners
35-
val jvmTest by getting {
36-
dependencies {
37-
implementation(kotlin("test-junit5"))
38-
implementation(libs.junit.jupiter.engine)
39-
runtimeOnly("org.junit.platform:junit-platform-launcher")
40-
}
41-
}
42-
val jsTest by getting {
59+
commonTest {
4360
dependencies {
44-
implementation(kotlin("test-js"))
61+
implementation(kotlin("test"))
4562
}
4663
}
4764
}
4865
}
4966

5067
configurePublishing()
5168

52-
tasks.withType<KotlinJvmTest> {
53-
useJUnitPlatform()
54-
}
55-
5669
detekt {
5770
buildUponDefaultConfig = true
5871
config.setFrom(files("detekt.yml"))
59-
autoCorrect = (findProperty("detektAutoCorrect") as String?)?.toBoolean() ?: true
60-
}
61-
dependencies {
62-
detektPlugins(libs.detekt.formatting)
72+
autoCorrect = booleanProperty("detektAutoCorrect", default = true)
6373
}
64-
tasks.withType<Detekt> {
65-
tasks.getByName("check").dependsOn(this)
74+
75+
tasks {
76+
withType<Detekt> {
77+
named("check") {
78+
dependsOn(this@withType)
79+
}
80+
}
6681
}

Diff for: buildSrc/build.gradle.kts

+4-10
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ plugins {
22
`kotlin-dsl`
33
}
44

5-
repositories {
6-
mavenCentral()
7-
gradlePluginPortal()
8-
}
9-
10-
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
115
dependencies {
12-
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.9.10")
13-
implementation("io.github.gradle-nexus:publish-plugin:1.3.0")
14-
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.findVersion("kotlin").get()}")
15-
}
6+
implementation(libs.dokka.plugin)
7+
implementation(libs.nexus.plugin)
8+
implementation(libs.kotlin.plugin)
9+
}

Diff for: buildSrc/settings.gradle.kts

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
dependencyResolutionManagement {
2+
@Suppress("UnstableApiUsage")
3+
repositories {
4+
mavenCentral()
5+
gradlePluginPortal()
6+
}
7+
28
versionCatalogs {
39
create("libs") {
410
from(files("../gradle/libs.versions.toml"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.github.petertrr.ext
2+
3+
import org.gradle.api.Project
4+
5+
/**
6+
* Returns a project property as a boolean (`"true" == true`, else `false`).
7+
*/
8+
fun Project.booleanProperty(name: String, default: Boolean = false): Boolean {
9+
val property = findProperty(name) ?: return default
10+
val propertyStr = property as? String ?: return default
11+
return propertyStr.trim().lowercase() == "true"
12+
}

Diff for: gradle/libs.versions.toml

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
[versions]
2-
kotlin = "1.9.22"
3-
junit = "5.10.1"
2+
kotlin = "1.9.23"
43
detekt = "1.23.5"
4+
dokka = "1.9.10"
5+
nexus = "1.3.0"
56

67
[plugins]
7-
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
88
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
99

1010
[libraries]
11-
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
12-
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
13-
detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }
11+
detekt-formatting = { group = "io.gitlab.arturbosch.detekt", name = "detekt-formatting", version.ref = "detekt" }
12+
13+
# Gradle plugins
14+
kotlin-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
15+
dokka-plugin = { group = "org.jetbrains.dokka", name = "dokka-gradle-plugin", version.ref = "dokka" }
16+
nexus-plugin = { group = "io.github.gradle-nexus", name = "publish-plugin", version.ref = "nexus" }

Diff for: settings.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ plugins {
1313
rootProject.name = "kotlin-multiplatform-diff"
1414

1515
dependencyResolutionManagement {
16+
@Suppress("UnstableApiUsage")
1617
repositories {
1718
mavenCentral()
1819
}

0 commit comments

Comments
 (0)