用于Gradle的Kotlin的kapt插件不适用于自定义源集(JMH) [英] Kotlin's kapt plugin for gradle does not work for custom source set (JMH)

查看:830
本文介绍了用于Gradle的Kotlin的kapt插件不适用于自定义源集(JMH)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用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 ,执行基准测试失败与:

 线程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's kapt configuration, just like compile and runtime do.

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

fixes the problem for me.

I expected it to be jmhKapt by analogy with jmhCompile, but this produces

Couldn't find method jmhCapt

这篇关于用于Gradle的Kotlin的kapt插件不适用于自定义源集(JMH)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆