https://kotlinlang.org logo
#kapt
Title
# kapt
s

Stéphane Nicoll

02/21/2019, 5:38 PM
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

tddmonkey

02/21/2019, 8:01 PM
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

Stéphane Nicoll

02/22/2019, 10:16 AM
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

tddmonkey

02/22/2019, 10:19 AM
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

Stéphane Nicoll

02/22/2019, 10:34 AM
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

tddmonkey

02/22/2019, 10:36 AM
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

tddmonkey

02/22/2019, 10:46 AM
Generate the input source code?
s

Stéphane Nicoll

02/22/2019, 11:05 AM
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

tddmonkey

02/22/2019, 11:06 AM
Ah, I see. I know of no better way than actually running kapt then