sbt / sbt-jmh

"Trust no one, bench everything." - sbt plugin for JMH (Java Microbenchmark Harness)
Apache License 2.0
787 stars 91 forks source link

Forking JMH may fail on Windows with "CreateProcess error=206, The filename or extension is too long" #241

Open piotrp opened 1 year ago

piotrp commented 1 year ago

It would be great if sbt-jmh included a workaround for running with long classpaths on Windows. Currently JMH is failing to fork benchmarks and prints:

<failed to invoke the VM, caught IOException: Cannot run program "C:\Program Files\Java\...\java.exe": 
CreateProcess error=206, The filename or extension is too long>

This can be worked around by adding this to my sbt configuration:

    Jmh / run / javaOptions ++= (
      if (System.getProperty("os.name").startsWith("Windows")) {
        Seq("-Djmh.separateClasspathJAR=true", "\"-Djava.io.tmpdir=" + target.value + "\"")
      } else
        Seq.empty
      ),

-Djmh.separateClasspathJAR=true tells JMH to package classpath into JAR file. Setting -Djava.io.tmpdir= is required if source files aren't on the same drive as temp directory - https://github.com/openjdk/jmh/blob/1.37/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java#L874.

johanandren commented 1 year ago

A PR would be welcome!