有一个带有 Gradle 设置的 Kotlin 项目:
apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'
dependencies {
kapt 'org.openjdk.jmh:jmh-generator-annprocess:1.18'
...
}
将基准放在src/main/kotlin下可以正常工作。
但是当我为 JMH 添加自定义源集时:
sourceSets {
jmh {
compileClasspath += sourceSets.test.runtimeClasspath
runtimeClasspath += sourceSets.test.runtimeClasspath
}
}
并将基准从src/main/kotlin 移动到src/jmh/kotlin,执行基准失败并显示:
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)
看起来 kaptJmhKotlin 没有做任何事情:
kaptGenerateStubsJmhKotlin UP-TO-DATE
Skipping task ':kaptJmhKotlin' as it has no source files and no previous output files.
:kaptJmhKotlin NO-SOURCE
:compileJmhKotlin
知道如何解决问题吗?