Hey there, I'm working on a compiler plugin which...
# compiler
m
Hey there, I'm working on a compiler plugin which generates new files in the AnalysisHandlerExtension. Everything works fine until I turn on incremental compilation. The problem is that the compiler has no idea about the relation between the generated files and their "originating files". The first compilation works fine. Then when a originating file changes, the compiler only compiles the originating file (Here I create a new generated file). But the compiler starts another compilation round and now compiles both the originating file and the generated file. And this is the problem. The compiler should not trigger another round only to recompile the two files from the previous round. I tried to cache the relations between the files and delete the generated ones, when ever a originating one changes, but this does not work, because the dirty generated files are already in the environment of the compiler. I also tried to manually remove the files via reflection but the compiler can't handle that. Another thing I tried is to just generate the file again, but this causes other issues, because the compiler analysis the old version of the file which may have errors in it. Is there a workaround for my issue?
r
There’s a ticket for the issue that if you change the compiler plugin, then the source code isn’t recompiled: https://youtrack.jetbrains.com/issue/KT-38570 I’ve implemented a workaround here: https://github.com/square/anvil/blob/main/gradle-plugin/src/main/java/com/squareup/anvil/plugin/DisableIncrementalCompilationTask.kt Anvil uses a 2nd workaround. For stub generation it always has to disable incremental compilation to pick up changes from the dependencies. This workaround is here: https://github.com/square/anvil/blob/main/gradle-plugin/src/main/java/com/squareup/anvil/plugin/AnvilPlugin.kt#L105-L119
m
Thanks for your reply. So basically the plugin runs without incremental compilation or did i miss something?
r
It disables incremental compilation for the tasks that would be otherwise broken. It doesn’t do this for all tasks.
m
Ok. Have you noticed any performance hits by doing that? Do you access descriptors or only psi elements?
r
Both. Sure, there’s a perf hit. Slack looked into the plugin and they saw a large increase. In our case it was minimal, because the modules in which we run Dagger and the compiler plugin are tiny.