Kapt: How to handle test sources?

I have a project that uses kapt to process annotations and generate code (based on annotations). It works in major sources, but not in test sources.

Some sources (for example, how to use kapt in the androidTest area ) offer to run gradle kaptTest, but this will not work either. He reports the mission as β€œUntil Now,” even immediately after cleaning. Perhaps this offer is unique to Android.

I downloaded a sample project from https://github.com/JetBrains/kotlin-examples/tree/master/gradle/kotlin-code-generation , added the use of annotations in test sources, and I got the same behavior there. It works well for major sources, and it does not work for test sources.

The only difference is the output:

> Task :example:compileKotlin
Using kotlin incremental compilation

w: [kapt] Sources output directory is not specified, skipping annotation processing

but, as you can see, these are not test sources, but the main sources and the annotation processor apply to them.

I added a printout to the annotation handler. It appears to compile Kotlin, but not to compileTestKotlin.

So what is the magic trick to do work on test sources?

PS: I think someone will ask for my build.gradle. It is identical to that of the example I gave, so if you can get it to work as an example, I can integrate into my build file.

PPS: , , kaptlin kapt gradle (JMH), . , kapt- gradle -plugin?

+4
1

(, kapt androidTest) gradle kaptTest, .

. , kaptTest kapt dependencies, , , gradle . OTOH, :

, kaptAndroidTest kaptTest kapt, kapt, , .

, .

https://youtrack.jetbrains.com/issue/KT-21891. , , Gradle/Kotlin/Kotlin gradle/etc. .

0

Source: https://habr.com/ru/post/1686306/


All Articles