JMH doesn't run inside a Java Module (Unable to find the resource: /META-INF/BenchmarkList)

烂漫一生 提交于 2019-12-24 10:18:15

问题


I took a project that uses maven-surefire-plugin (automated tests) to trigger JMH benchmarks and added module-info.java to it. Now, META-INF/BenchmarkList is no longer getting generated (in fact, the entire directory is missing) so I end up with the following error when launching the benchmarks:

ERROR: Unable to find the resource: /META-INF/BenchmarkList

I suspect that Java Modules is preventing the annotation processor from running properly, but I can't figure out how to fix it. Any ideas?


回答1:


I figured it out through trial and error. It looks like a bug (or "feature") in maven-compiler-plugin 3.8.0. When module-info.java is present, the JMH annotation processor is no longer picked up automatically. Adding this configuration fixed the problem for me:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
    [...]
        <annotationProcessorPaths>
            <path>
                <groupId>org.openjdk.jmh</groupId>
                <artifactId>jmh-generator-annprocess</artifactId>
                <version>${jmh.version}</version>
            </path>
        </annotationProcessorPaths>
    [...]
    </configuration>
</plugin>

UPDATE: I filed a bug report against maven-compiler-plugin.



来源:https://stackoverflow.com/questions/53927874/jmh-doesnt-run-inside-a-java-module-unable-to-find-the-resource-meta-inf-ben

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!