I have a Kotlin Multiplatform project built with Gradle (.kts
). One of the targets is jvm()
.
For that target I also have a Java library with custom annotations that I need to use. However, when I just put these annotations in my Kotlin code, as far as I can tell, they don't get processed. I am assuming the problem is that the library custom annotation processor is not registered and does not run on my Kotlin code. At the same time,
The question is: how do I register it?
- I tried setting javac
-processor
argument, but I couldn't find a way to add it from Gradle build file. The best I could do was the deeply buriedcompilations.getByName("main").compilationOptions.options.freeCompilerArgs
, but it turned out to be Kotlin compiler arguments. - I looked for java-specific build features, like
annotationProcessor
from another question. They are nowhere to be found since I don't have a dedicated Java plugin and/or source set. - I found
-Xjavac-arguments
parameter ofkotlinc-jvm
, but not only is it experimental (basically a developer tool), but it is also apparently just broken and does nothing. - I tried random placements of
META-INF/services/javax.annotation.processing.Processor
as described in this guide, which quite expectably didn't work either.
At the same time, JUnit's @Test
annotations work without any problems, so it should be doable. What am I missing?
UPD: I found that jvm().dependencies
does have annotationProcessor()
in it, and I also saw that META-INF of the library I'm using does have the necessary processor declared. Although this seems like a proper solution, I'm still getting the same failing behavior. How can I verify that the library processor ran or not?