Kotlin kapt plugin for gradle does not work for custom source (JMH)

The presence of the Kotlin project with Gradle configuration:

apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'

dependencies {
    kapt 'org.openjdk.jmh:jmh-generator-annprocess:1.18'
    ...
}

Setting tests in src / main / kotlin works without problems.

But when I add a custom source for JMH:

sourceSets {
    jmh {
        compileClasspath += sourceSets.test.runtimeClasspath
        runtimeClasspath += sourceSets.test.runtimeClasspath
    }
}

And transfer the tests from src / main / kotlin to src / jmh / kotlin, the tests are not executed:

Exception in thread "main" java.lang.RuntimeException: ERROR: Unable to find the resource: /META-INF/BenchmarkList
    at org.openjdk.jmh.runner.AbstractResourceReader.getReaders(AbstractResourceReader.java:98)
    at org.openjdk.jmh.runner.BenchmarkList.find(BenchmarkList.java:122)
    at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:256)
    at org.openjdk.jmh.runner.Runner.run(Runner.java:206)
    at org.openjdk.jmh.Main.main(Main.java:71)

It seems that kaptJmhKotlin does nothing:

kaptGenerateStubsJmhKotlin UP-TO-DATE
Skipping task ':kaptJmhKotlin' as it has no source files and no previous output files.
:kaptJmhKotlin NO-SOURCE
:compileJmhKotlin

Any idea how to solve the problem?

+2
source share
1 answer

kaptin this context defines the relationship to the primary source configuration kapt, as well compile, and runtimedo.

dependencies {
  kaptJmh 'org.openjdk.jmh:jmh-generator-annprocess:1.18'
}

fixes the problem for me.

I expected it to be jmhKaptsimilar to jmhCompile, but it gives

Couldn't find method jmhCapt
+2
source

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


All Articles