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

1

4

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?

Piracy answered 26/12, 2018 at 5:41 Comment(1)
In general, it's really tough to figure out the error or its cause when there is not an MCVE with the question though. Just sharing this since the question starts with maven-surefire and the answer ends it with maven-compiler instead.Length
P
17

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.

Piracy answered 26/12, 2018 at 6:48 Comment(3)
Worked for me too after mvn clean install.Paulson
what is the value of jmh.version?Tailored
@LizLamperouge Whatever version of JMH you want to use.Piracy

© 2022 - 2024 — McMap. All rights reserved.