← thecodex.expert · The Codex Family of Knowledge
Kotlin

Build Tools

A typo in an old Groovy build.gradle file often surfaced as a confusing runtime failure — the same mistake in build.gradle.kts is a compile error, caught by the IDE before the build even runs.

Kotlin 2.1 Kotlin DSL now standard over Groovy Last verified:
Canonical Definition

Gradle originally used Groovy for build scripts (build.gradle) — dynamically typed, with limited IDE support for catching mistakes before running the build. build.gradle.kts, Gradle's Kotlin DSL, is now the standard choice for new projects: the same statically-typed benefits Kotlin brings everywhere else apply directly to the build script, including full autocomplete and compile-time errors for a misspelled configuration option. Version catalogs (gradle/libs.versions.toml) centralize every dependency's version in one shared file, referenced consistently across every module in a multi-module project, rather than duplicating version strings throughout many build files.

build.gradle.kts: a typed, IDE-friendly build script

Misspelling implementation as implemantation, or a dependency coordinate, is caught immediately by the IDE here — the equivalent mistake in the older Groovy DSL often wouldn't surface until the build actually ran and failed.

Kotlinbuild.gradle.kts
plugins {
    kotlin("jvm") version "2.4.0"
    application
}

dependencies {
    implementation("com.squareup.okhttp3:okhttp:4.12.0")
    testImplementation(kotlin("test"))
}

application {
    mainClass.set("com.example.MainKt")
}

Version catalogs: one shared source of truth

Every module in a multi-module project references libs.okhttp instead of repeating the exact version string — updating one entry in the catalog updates it everywhere it's used, avoiding version drift between modules.

Kotlingradle/libs.versions.toml
[versions]
okhttp = "4.12.0"

[libraries]
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
Kotlinbuild.gradle.kts
dependencies {
    implementation(libs.okhttp)   // references the catalog entry, not a hardcoded version
}

Multi-module project structure

settings.gradle.kts declares which modules exist; each module gets its own build.gradle.kts, letting a large project split cleanly into independently-buildable pieces (a shared library, an app module, and so on).

Kotlinsettings.gradle.kts
rootProject.name = "my-project"
include(":app", ":shared-lib")

Sources

1
JetBrains. Kotlin Documentation, "Get started with Gradle," kotlinlang.org/docs/gradle.html, and Gradle documentation on version catalogs.