Kotlin DSL "Script compilation error" in build.gradle.kts in CI
Gradle compiles build.gradle.kts as Kotlin before running it. A "Script compilation error" means the build script did not type-check: a plugin that provides an extension was not applied, a type accessor is missing, or an API changed across Gradle versions.
What this error means
Configuration fails immediately with "Script compilation error:" and one or more "Unresolved reference" lines pointing at your build.gradle.kts, before any task runs.
FAILURE: Build failed with an exception.
* Where: Build file '/app/build.gradle.kts' line: 24
* What went wrong:
Script compilation error:
Line 24: kotlinOptions { jvmTarget = "17" }
^ Unresolved reference: kotlinOptionsCommon causes
A plugin that provides the accessor is not applied
DSL accessors like kotlinOptions, android, or kotlin { } only exist after the plugin is applied in the plugins {} block. Without it, the script does not compile.
An API changed between Gradle or plugin versions
CI resolved a newer Gradle or Kotlin plugin that removed or renamed a DSL entry (for example kotlinOptions moving to compilerOptions), breaking the script that compiled on the old version.
How to fix it
Apply the plugin so accessors exist
- Confirm the plugin that owns the missing accessor is in
plugins {}. - Move plugin application above the block that uses its DSL.
- Re-run configuration to confirm the script compiles.
plugins {
kotlin("jvm") version "2.0.21"
}
kotlin {
compilerOptions { jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17) }
}Match the DSL to the Gradle/plugin version
Check the plugin release notes for renamed DSL entries and update the script to the API the resolved version exposes.
./gradlew help --scanHow to prevent it
- Pin Gradle (via the wrapper) and plugin versions so DSL accessors are stable.
- Keep
plugins {}applications before the blocks that use their accessors. - Read plugin migration notes before bumping the Kotlin Gradle plugin.