3

I have a Kotlin annotation processor library which generates some classes and writes them with

    FileSpec.builder(...)
        ...
        .build()
        .writeTo(processingEnv.filer)

The generated files end up in build/generated/source/kapt/.... They are only recognized by gradle if I add kotlin.srcDir("${buildDir.absolutePath}/generated/source/kapt/") to my build.gradle.kts.

It works the same way if I use kapt.kotlin.generated option - the path changes to build/generated/source/kaptKotlin/... but I still need to explicitly add the path to sources dir for the gradle to use these files during build process. Otherwise it's not only unrecognized by gradle, but also by Intellij.

Important note: my processor works in a Kotlin Multiplatform module.

I don't see necessity to include the generated source dirs with codegen libraries like dagger or moshi - they seem to just write to processingEnv.filer and everything works automagically.

So there must either be some additional configuration which makes it possible to omit the explicit kotlin.srcDir... or there is some limitation of KMM project. Any idea what the fix might be?

Michał Klimczak
  • 12,674
  • 8
  • 66
  • 99

0 Answers0