Skip to content
Latchkey

Gradle "Execution failed for task :kaptKotlin (KaptWithoutKotlincTask)" - Fix in CI

Kotlin's kapt (Kotlin Annotation Processing Tool) failed while generating stubs or running processors. Common roots are a JDK too new for the kapt/Kotlin version, a processor not declared on the kapt configuration, or an error in the code kapt is processing.

What this error means

The build fails with Execution failed for task ':app:kaptGenerateStubsKotlin' or :kaptKotlin, often wrapping a java.lang.IllegalAccessError/ExceptionInInitializerError from kapt running on a JDK it does not support.

gradle
> Task :app:kaptGenerateStubsKotlin FAILED

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:kaptGenerateStubsKotlin'.
> Could not resolve all files for configuration ':app:kapt'.
  > error: cannot access class file for processor ...

Common causes

Processor missing from the kapt configuration

kapt only runs processors declared with kapt "..."; one added via implementation is ignored or fails resolution.

JDK newer than kapt supports

Older kapt needs --add-opens on newer JDKs; without it, stub generation throws an access error.

Error in generated/annotated code

An invalid annotation usage or a processor bug surfaces as a kapt task failure rather than a normal compile error.

How to fix it

Declare processors on the kapt configuration

Add each annotation processor with the kapt configuration so kapt runs it.

gradle
plugins { id 'org.jetbrains.kotlin.kapt' }
dependencies {
  implementation 'com.google.dagger:dagger:2.51'
  kapt 'com.google.dagger:dagger-compiler:2.51'
}

Open JDK internals for kapt on new JDKs

Pass the add-opens kapt needs when running on JDK 17/21.

properties
# gradle.properties
kapt.use.jvm.ir=true
org.gradle.jvmargs=--add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
  --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED

Consider migrating to KSP

KSP is faster and avoids kapt's stub generation entirely where the processor supports it.

gradle
plugins { id 'com.google.devtools.ksp' version '2.0.20-1.0.25' }
dependencies { ksp 'com.example:my-processor:1.0' }

How to prevent it

  • Declare every processor on kapt/kaptTest.
  • Keep Kotlin, kapt, and the JDK on a supported combination.
  • Prefer KSP over kapt for processors that support it.

Related guides

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