what are the differences between `kapt` and `kaptK...
# kapt
m
what are the differences between
kapt
and
kaptKotlin
directories in
generated/source
? When should I use one or the other? Can't really find anything about it. Dagger and moshi seem to generate to
kapt
. From my tests it seems that I need to manually tell gradle where to look for these files for either of these (via
kotlin.srcDir("${buildDir.absolutePath}/generated/source/kapt/")
or
kotlin.srcDir("${buildDir.absolutePath}/generated/source/kaptKotlin/")
. Yet it doesn't seem to be necessary for dagger etc. If that makes any difference, I'm asking about kotlin multiplatform module.
The only difference I see is that
kaptKotlin
is not properly marked as generated sources root in my android studio, but that might be unrelated
t
It’s been a while since I’ve written an annotation processor so take what I say with a grain of salt - but I believe that each processor either defines or makes configurable where any sources are output to. So the difference between the above is just that the processors output to different locations
Ah - looks like my info is slightly out of date.
Copy code
Kapt can generate Kotlin sources. Just write the generated Kotlin source files to the directory specified by processingEnv.options["kapt.kotlin.generated"], and these files will be compiled together with the main sources.
https://kotlinlang.org/docs/reference/kapt.html
m
thank you for responding! I do exactly that and write the generated files to a file that I get from
processingEnv.options["kapt.kotlin.generated"]
but the client of my processor still needs to explicitly use
kotlin.srcDir("${buildDir.absolutePath}/generated/source/kaptKotlin/")
in his build.gradle. On the other hand, moshi writes files to
processingEnv.filer
and they end up in
/generated/source/kapt/
, but they don't seem to require the
kotlin.srcDir
to be explicitly set. When I do the same thing,
kotlin.srcDir("${buildDir.absolutePath}/generated/source/kapt/")
is required. It's either a kotlin multiplatform thing or some kind of additional configuration that I cannot find.
t
tbf writing annotation processors does end up being a lot of trial and error as the docs aren’t brilliant
😞 1
114 Views