Skip to content
Latchkey

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.

Gradle
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: kotlinOptions

Common 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

  1. Confirm the plugin that owns the missing accessor is in plugins {}.
  2. Move plugin application above the block that uses its DSL.
  3. Re-run configuration to confirm the script compiles.
build.gradle.kts
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.

Terminal
./gradlew help --scan

How 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.

Frequently asked questions

What causes ""Script compilation error" (build.gradle.kts)"?
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.
How do I fix "Script compilation error" (build.gradle.kts)?
Apply the plugin so accessors exist

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card