If I need to generate files as part of a compiler ...
# compiler
y
If I need to generate files as part of a compiler plugin (i.e. in an AnalysisHandler) where should I place those generated sources? currently I'm just using the first source file I find and creating a new directory in its directory, but obviously that's extremely error-prone. I basically just want to somehow get a hold of the
build/generated/source
directory I guess but in a way that also works if
kotlinc
was called from the command-line with my plugin. I'm seriously hoping that there is a way to do this. It seems as though what
kapt
does for example is to just have a hard-coded value based on the gradle project.buildDir, but I'm trying to make this work in the case that gradle is for some reason not there.
s
You can pass the directory as a parameter to the compiler cli, and use a gradle plugin to get
buildDir
.
I don't remember the name of the extension point atm, maybe something related to CommandLineProcessor?
j
I have been following this guide and that is what is done, pass from gradle to the commandline processor: https://blog.bnorm.dev/writing-your-second-compiler-plugin-part-1