Hi,
I am using kapt with maven and a java annotation processor and that is good.
However, ideally instead of the annotation processor generating Java source I’d like it to generate Kotlin (to make use of Kotlin properties rather than java methods). To play around with this I’ve done a little hack to modify my annotation processor to generate Kotlin code rather than Java and it “sort of works”.
That is:
- The Java processingContext.createWriter() … creates a .java file
- My annotation processor generates Kotlin source into that .java file
- I rename the .java file to be .kt after the source has been written
… yes this is a bit hacky but worth a try right.
In the IDE is seems to be all fine - things all compile etc. However, in maven command like I see the kapt compile reporting errors - the xx.java file can’t be found which sounds reasonable given I renamed the file to be .kt.
[INFO] --- kotlin-maven-plugin:1.1.2:kapt (kapt) @ example-kotlin ---
[INFO] Kotlin Compiler version 1.1.2
[INFO] Compiling Kotlin sources from [/home/rob/github/ebean-dir/examples/example-kotlin/src/main/java]
[INFO] Module name is example-kotlin
... I log that I am rename the generated file from .java to .kt
[INFO] Note: rename from file:/.../example-kotlin/target/generated-sources/kapt/compile/org/example/domain/query/QOrder.java partial:QOrder to file /.../examples/example-kotlin/target/generated-sources/kapt/compile/org/example/domain/query/QOrder.kt
I see the error:
[ERROR] error: error reading /.../examples/example-kotlin/target/generated-sources/kapt/compile/org/example/domain/query/QOrder.java; /.../examples/example-kotlin/target/generated-sources/kapt/compile/org/example/domain/query/QOrder.java (No such file or directory)
… which is reasonable given I renamed the generated file to be .kt
A this point I can run in the IDE fine - build all compiles fine, run tests using the generated kotlin code etc.
I’d really like to be able to generate Kotlin code with my annotation processor rather than Java code. The generated code in this case are “query beans” for an ORM and it is much nicer to use Kotlin property support compared to java methods in this case (much much nicer, that is another story).
Are there any plans for supporting kapt with generated Kotlin code?
If kapt could look for .kt generated files as well as .java it looks like it would just work?
Thanks, Rob.