用于Gradle的Kotlin的kapt插件不适用于自定义源集(JMH) [英] Kotlin's kapt plugin for gradle does not work for custom source set (JMH)
问题描述
apply plugin:'kotlin'
apply plugin:'kotlin -kapt'
dependencies {
kapt'org.openjdk.jmh:jmh-generator-annprocess:1.18'
...
}
将基准放在 src / main / kotlin 下工作没有问题。
但是,当我为JMH添加自定义源集时:
sourceSets {
$然后将基准从 src / main / kotlin 移动到 src / jmh / kotlin ,执行基准测试失败与:
jmh {
compileClasspath + = sourceSets.test.runtimeClasspath
runtimeClasspath + = sourceSets.test.runtimeClasspath
}
}
线程main中的异常java.lang.RuntimeException:错误:无法找到资源:/ META-INF / BenchmarkList
at org.openjdk.jmh.runner.AbstractResourceReader.getReaders(AbstractReso urceReader.java:98)
at org.openjdk.jmh.runner.BenchmarkList.find(BenchmarkList.java:122)
at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:
at org.openjdk.jmh.runner.Runner.run(Runner.java:206)
at org.openjdk.jmh.Main.main(Main.java:71)
它看起来像kaptJmhKotlin没有做任何事情:
kaptGenerateStubsJmhKotlin UP-TO-DATE
跳过任务':kaptJmhKotlin',因为它没有源文件,也没有以前的输出文件。
:kaptJmhKotlin NO-SOURCE
:compileJmhKotlin
任何想法如何解决在此上下文中定义了一个依赖关系:
解决方案
em>主要源代码集的
>,但是这会产生kapt
配置,就像compile
和
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $'$ $ $ $' generator-annprocess:1.18'
}
解决了我的问题。
通过与
jmhCompile
jmhKapt找不到方法jmhCapt
Having a Kotlin project with Gradle setup:
apply plugin: 'kotlin' apply plugin: 'kotlin-kapt' dependencies { kapt 'org.openjdk.jmh:jmh-generator-annprocess:1.18' ... }
Putting benchmarks under src/main/kotlin works without problems.
But when i add a custom source-set for JMH:
sourceSets { jmh { compileClasspath += sourceSets.test.runtimeClasspath runtimeClasspath += sourceSets.test.runtimeClasspath } }
And move the benchmarks from src/main/kotlin to src/jmh/kotlin, executing the benchmarks fails with:
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 looks like kaptJmhKotlin isn't doing anything:
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 resolve the problem ?
解决方案
kapt
in this context defines a dependency for the main source set'skapt
configuration, just likecompile
andruntime
do.dependencies { kaptJmh 'org.openjdk.jmh:jmh-generator-annprocess:1.18' }
fixes the problem for me.
I expected it to be
jmhKapt
by analogy withjmhCompile
, but this producesCouldn't find method jmhCapt
这篇关于用于Gradle的Kotlin的kapt插件不适用于自定义源集(JMH)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文