Search code examples
kotlinremote-debuggingannotation-processingannotation-processorkapt

Can't Debug an Annotation Processor when using kapt and gradle


I'm building an annotation processor, and I recently switched from using the default annotationProcessor type to kapt, using the kotlin-kapt plugin.

I was debugging my processor by using the command

./gradlew --no-daemon -Dorg.gradle.debug=true :app:clean :app:compileDebugJavaWithJavac

(full instructions here: https://stackoverflow.com/a/42488641/502463 )

And then running a Remote debugging configuration. When I used annotationProcessor, I could hit breakpoints, and debug fine. with kapt, my processor runs, but I can't debug it. No breakpoints are triggered.

My kotlin version is 1.1.2-3


Solution

  • You actually want to debug the Kotlin compiler daemon, not the Gradle daemon. Here is how you can pass the required JVM arguments:

    ./gradlew <tasks> -Dkotlin.daemon.jvm.options="-Xdebug,-Xrunjdwp:transport=dt_socket\,address=5005\,server=y\,suspend=n"