melix / jmh-gradle-plugin

Integrates the JMH benchmarking framework with Gradle
Apache License 2.0
662 stars 88 forks source link

Adds environment variables #211

Closed bric3 closed 2 years ago

bric3 commented 2 years ago

Sometimes it is necessary to pass some environment variables to configure the JVM process (in particular when native libraries are involved). And when there's no system property equivalent, or when it's not possible to do in the benchmark setup (e.g. LD_PRELOAD, JAVA_LIBRARY_PATH).

Alas, JMH does not support to set environment variable on the forked process, however it will propagate the ones that it has been launched with. E.g.

env JAVA_LIBRARY_PATH=/somewhere java -jar bench.jar

This change aims at providing the ability to pass the variable to JMH so it cna be used on the JMH forked process.

bric3 commented 2 years ago

I'd like something closer to the JavaExecSpec, but the jmh block is not extending it.

environment(mapOf("JAVA_HOME" to System.getenv("JAVA_HOME")))
environment("JAVA_HOME", System.getenv("JAVA_HOME"))

And I am not sure how best to proceed. Same for the tests.

bric3 commented 2 years ago

Wrong branch on my side, see #212 instead.