Hey everyone, I am looking for a sample or best pr...
# kapt
s
Hey everyone, I am looking for a sample or best practices to test an annotation processor with Kotlin. I’ve something that works quite well for Java and was wondering how I could do the same with Kotlin (knowing that I’ll probably have to do something kotlin specific in there)
t
I’ve been looking at that lately. Ended up using Avatar where I could, but you need Java code for that, then backing off to a multi-module project and having the tests in the second module, depending on kapt being run first
s
Thanks for the reply. Do you have a sample somewhere?
It’s a general-purpose library that supports primarily Java with official support for Kotlin so we’re trying to make sure our stuff works in an idiomatic way with Kotlin
I guess I can live with the separate modules for the kotlin-specific tests even if that makes debugging quite annoying.
t
I don’t have a sample as it’s not open-sourced at the moment
The secondary module testing wasn’t that much, just places where kotlin differs in a way you can’t replicate in Java
s
How does that work practically? You’re generating kapt in the second module and then compiling the generated java source?
I was hoping I could do that from the test actually
t
Copy code
module 1 -> the annotation processor
    -> Avatar for unit testing.  Java sources in `src/test/java` that have the annotation processor applied.  Avatar lets you inspect the output/processing
module 2 -> the other tests
     -> Run `kapt`, have tests verify the output of the annotation processor.
Within module 1 it’s a standard test cycle, Avatar runs from within the test so it’s just a case of running the test/modifying the code/running the test. Module 2 requires kapt to run so it’s more long winded
I guess I need a way to generate the Java source code (I don’t need to trigger the AP really, I can do that once the Java source code has been generated)
t
Generate the input source code?
s
The javasource code that kapt generates from the kotlin counter part
If I have that, I am happy as I can run the compiler the same way I do for the Java stuff
t
Ah, I see. I know of no better way than actually running kapt then