Skip to content
Latchkey

Kotlin "Unresolved reference" in CI

The Kotlin compiler hit a name it cannot resolve. The class, function, or property you used is not on the compile classpath or is not imported.

What this error means

The build fails with Unresolved reference: foo, pointing at the symbol. It is deterministic - the name is simply not visible to the compiler.

gradle
e: file:///src/main/kotlin/App.kt:5:8 Unresolved reference: gson
e: file:///src/main/kotlin/App.kt:12:14 Unresolved reference: toJson

Common causes

Dependency missing or wrong configuration

Using a library without adding it to implementation, or adding it only to testImplementation, leaves it off the main classpath.

Missing import

The symbol exists but the file does not import it, or the package was mistyped.

Generated code not built yet

References to kapt/ksp-generated or BuildConfig symbols fail if the generating task did not run before Kotlin compilation.

How to fix it

Add the dependency to the right configuration

build.gradle.kts
dependencies {
  implementation("com.google.code.gson:gson:2.11.0")
}

Add the missing import

  1. Confirm the fully qualified name of the symbol.
  2. Add the matching import statement.
  3. Re-sync Gradle so the IDE and CI agree on the classpath.

Ensure generators run before compile

Make the Kotlin compile task depend on the kapt/ksp/BuildConfig task so generated code exists first.

How to prevent it

  • Keep dependency configurations correct.
  • Run ./gradlew compileKotlin on a clean checkout.
  • Verify generated sources are wired into the build.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →