Debug Annotation Processor Kapt


does anyone have experience with debugging custom annotation processors? I’m not able to figure out how to do it.
Based on this SO thread I started gradle using

./gradlew --no-daemon -Dorg.gradle.debug=true -Dkotlin.daemon.jvm.options="-Xdebug,-Xrunjdwp:transport=dt_socket\,address=5005\,server=y\,suspend=n" :clean assemble

Also it looks like I am able to connect to it using idea’s remote debug configuration.
The problem I have is that it does not seem to hit my breakpoint.

Any help is appreciated. I really don’t want to have to use print statements for debugging :wink:


By default all Kotlin tasks run in Kotlin Compile Daemon, which is a separate process.

This argument:


tells Kotlin to start a daemon process, which will listen on 5005 port for a debugger.

org.gradle.debug=true tells Gradle to start a process, which will listen on 5005 port for a debugger.

Two processes cannot listen on the same port, so you should specify a different port for Kotlin daemon.
Alternatively you can simply omit -Dorg.gradle.debug=true, since KAPT runs APs in Kotlin daemon.

If you’re using Kotlin 1.3.20, you can also add kapt.use.worker.api=true to Gradle properties, and debug Gradle process instead. Note that only with 1.3.20 kapt.use.worker.api runs KAPT in-process (before this option used Gradle Worker Processes by default).