Skip to content

Commit

Permalink
Update build configuration to reflect KGP improvements (#102)
Browse files Browse the repository at this point in the history
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
lppedd authored Mar 28, 2024
1 parent 2d978a9 commit b370f69
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 47 deletions.
77 changes: 46 additions & 31 deletions build.gradle.kts
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)
}
}
}
14 changes: 4 additions & 10 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
gradlePluginPortal()
}

val libs = extensions.getByType<VersionCatalogsExtension>().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()}")
}
implementation(libs.dokka.plugin)
implementation(libs.nexus.plugin)
implementation(libs.kotlin.plugin)
}
6 changes: 6 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
repositories {
mavenCentral()
gradlePluginPortal()
}

versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
Expand Down
12 changes: 12 additions & 0 deletions buildSrc/src/main/kotlin/io/github/petertrr/ext/Project.ext.kt
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"
}
15 changes: 9 additions & 6 deletions gradle/libs.versions.toml
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" }
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plugins {
rootProject.name = "kotlin-multiplatform-diff"

dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
repositories {
mavenCentral()
}
Expand Down

0 comments on commit b370f69

Please sign in to comment.