Troubleshooting incremental compilation

What is the best way to troubleshoot Kotlin’s incremental compilation, especially when paired with kapt?

With my current Android project it seems like IC will randomly fail and Gradle/Kotlin will decide it is good idea to generate stubs, kapt and compile kotlin from scratch, wasting minutes. I want to find the cause, but I’m at loss on how to start. Does Kotlin compiler provide any logs or hooks for that?

Hello. Since is not done yet, you can troubleshoot IC like this: How to ensure that incremental compilation works for me - #2 by tsvetkov.

Yes, I’ve seen that topic. However that method only seems to work for compileKotlin, not for generateStubs. With kapt involved, compileKotlin will always compile bunch of files since kapt is not incremental. Stubs would be much more useful to check here.

Also, it only lists the files that were compiled with no clue on why they were compiled.

If the scenario is reproducible, you can try to run Gradle with --debug. However the debug log level generates really a lot of logs and usually results in a significant overhead.

Sadly there is no other way for now (you may also debug the compiler, but it’s not easy either).

I plan to make some progress on KT-12700 for 1.3.20. Please watch the issue.