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.