Hello, I would like to use the compiler in a gradl...
# compiler
f
Hello, I would like to use the compiler in a gradle plugin, to process individual Kotlin files and extract the comments. I have been using Dokka Analysis for that in Kotlin 1.8, but it has been removed with no replacement provide, so I thought this may be the way to go. I guess I should add the kotlin-compiler-embeddable to my dependencies but I am not sure how to invoke it to parse a single file. Could you give me any pointers?
t
Hi! While it would be possible to start the whole compiler in the gradle plugin, it might be better to write an compiler plugin called by the compiler. IIRC you can get the comments from the FIR. You might want to check these: https://medium.com/google-developer-experts/crash-course-on-the-kotlin-compiler-1-frontend-parsing-phase-9898490d922b https://github.com/demiurg906/kotlin-compiler-plugin-template.git
f
Thank you! I have written compiler plugins before, but I was looking for a way to avoid it, as it would be part of a process that process different elements (including Kotlin files) to produce some comprehensive documentation, and I did not want to tie that to the compilation process of the Kotlin code. I was hoping to have something separate, that does the bare minimum parsing necessary for comments extraction
t
Maybe https://github.com/tschuchortdev/kotlin-compile-testing can give some inspiration? It let's you call the compiler from unit tests, so calling it from a gradle plugin would be also possible.
f
Thank you, I will look into this