Part 11 / Topic 3 of 9
Gradle with the Kotlin DSL — read conceptually, not run here
build.gradle.kts and settings.gradle.kts describe the project; gradle/./gradlew reads
them and does the work. Since Gradle isn't installed on this machine, these two files are
written to the real, documented shape — but nobody has run gradle build against them
here. Treat them as "what you'd write," not "what was tested."
settings.gradle.kts — names the project (and, in a multi-module build, lists every module):
rootProject.name = "discount-calculator"
build.gradle.kts — configures this one module:
plugins {
kotlin("jvm") version "2.4.21"
}
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit5"))
testImplementation("org.junit.jupiter:junit-jupiter-params:5.14.4")
}
kotlin {
jvmToolchain(21)
}
tasks.test {
useJUnitPlatform()
}
| Block | What it means |
|---|---|
plugins { kotlin("jvm") ... } |
Turns on Kotlin/JVM compilation — compileKotlin, test, and friends become real tasks |
repositories { mavenCentral() } |
Where to download dependencies from |
dependencies { testImplementation(...) } |
Libraries only src/test/kotlin can see — kotlin("test") is shorthand for the org.jetbrains.kotlin:kotlin-test Maven coordinate |
kotlin { jvmToolchain(21) } |
Pins the JDK version the build compiles and runs against |
tasks.test { useJUnitPlatform() } |
Tells Gradle's test task to run tests through the JUnit 5 engine, not the older JUnit 4 runner |
Running ./gradlew test (the Gradle wrapper, a script committed to the repo that pins an
exact Gradle version so every contributor and CI machine uses the same one) would then resolve
those three dependencies, compile both source sets, and run every test — exactly what section 7
below does by hand, one Gradle-sized step at a time.
Done here? The practice set for Part 11 — including the solutions — is on the part page.