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

Diagnose it: which runtime is on PATH?

Terminal
which -a <runtime>
<runtime> --version
cat .tool-versions .nvmrc .ruby-version .python-version 2>/dev/null

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.

Frequently asked questions

What causes Kotlin "Unresolved reference" in CI?
There are 3 common causes: dependency missing or wrong configuration, missing import, and generated code not built yet. Using a library without adding it to implementation, or adding it only to testImplementation, leaves it off the main classpath.
How do I fix Kotlin "Unresolved reference" in CI?
There are 3 fixes depending on which cause you have: add the dependency to the right configuration, add the missing import, and ensure generators run before compile. Work through them in order, since the first is the most common.
What does Kotlin "Unresolved reference" in CI actually mean?
The build fails with Unresolved reference: foo, pointing at the symbol.
How do I stop Kotlin "Unresolved reference" in CI happening again?
Keep dependency configurations correct. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card