Skip to content
Latchkey

Gradle "KotlinReflectionNotSupportedError" - Fix kotlin-reflect in CI

Code used Kotlin reflection, but the kotlin-reflect library is not on the runtime classpath. The base Kotlin stdlib ships only minimal reflection; full reflection needs the separate kotlin-reflect artifact, which is missing here.

What this error means

A test or app run throws kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath. It compiles fine; it fails at runtime.

stack trace
kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation
is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath
	at kotlin.jvm.internal.ClassReference.error(ClassReference.kt:...)

Common causes

kotlin-reflect not on the runtime classpath

Something (Jackson Kotlin module, a framework, or your code) calls full Kotlin reflection, but org.jetbrains.kotlin:kotlin-reflect is not a declared dependency, so it is absent at runtime.

Version skew between stdlib and reflect

If kotlin-reflect is present but at a different version than the Kotlin stdlib, reflection can still fail to initialize. They must match.

How to fix it

Add kotlin-reflect matching your Kotlin version

Declare the reflect artifact so it is on the runtime classpath, at the same version as the stdlib.

build.gradle.kts
dependencies {
    implementation(kotlin("reflect"))   // matches the Kotlin plugin version
}

Confirm it is actually on the runtime classpath

Check the runtime configuration resolves kotlin-reflect at the expected version.

Terminal
./gradlew :app:dependencies --configuration runtimeClasspath | grep kotlin-reflect

How to prevent it

  • Add kotlin("reflect") whenever code or a library uses full Kotlin reflection.
  • Keep kotlin-reflect and the Kotlin stdlib on the same version (the Kotlin plugin aligns them).
  • Cover reflection-using code paths in tests so the missing jar surfaces in CI, not production.

Frequently asked questions

What causes ""KotlinReflectionNotSupportedError""?
Something (Jackson Kotlin module, a framework, or your code) calls full Kotlin reflection, but org.jetbrains.kotlin:kotlin-reflect is not a declared dependency, so it is absent at runtime.
How do I fix "KotlinReflectionNotSupportedError"?
Declare the reflect artifact so it is on the runtime classpath, at the same version as the stdlib.

Related guides

References

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