Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 371
M Dapp Avatar asked May 22 '17 17:05

M Dapp


People also ask

What is kapt in gradle?

Kapt is the Kotlin Annotation Processing Tool, and it's in pretty good shape these days. If you want to be able to reference generated code from Kotlin, you need to use kapt. To do that, simply include the plugin in your build.gradle file with the line: apply plugin: 'kotlin-kapt'

Is kotlin kapt deprecated?

Is kapt deprecated? app: Original kapt is deprecated. Please add "apply plugin: 'kotlin-kapt'" to your build. gradle.

What is gradle annotation processor?

Annotation processing is a Java compilation option which has been around since Java 5. It enables the generation of additional files during compilation, such as classes or documentation.


2 Answers

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"
like image 94
yanex Avatar answered Sep 28 '22 06:09

yanex


I just tried to debug a Kotlin annotation processor and found this post. You can tell the JVM to wait for the debugger by passing suspend=y

What I do now is starting the build from command line:

./gradlew --no-daemon clean build -Dkotlin.daemon.jvm.options="-Xdebug,-Xrunjdwp:transport=dt_socket\,address=5005\,server=y\,suspend=y"

and then attaching with Intellij via remote configuration.

like image 26
Max Holtzberg Avatar answered Sep 28 '22 05:09

Max Holtzberg