How to pass jvm arguments in a Jenkins build using Gradle 8.6?

45 views Asked by At

I have recently upgraded an Openshift application to Java 17 and Gradle 8.6. The app uses the jacoco plugin to run unit test coverage over the code. The majority of the tests pass, but a few of them fail with this error :

java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible: module java.base does not "opens java.util" to unnamed module @31ea9581

Based on a number of other posts, the way to correct this is by passing the JVM "--add-opens java.base/java.util=ALL-UNNAMED" as a param. I can create a Windows Env var JDK_JAVA_OPTIONS with that string and the tests work locally. However, I can’t get our Jenkins build system to pick up the arg correctly. I’ve tried adding org.gradle.jvmargs=--add-opens java.base/java.util=ALL-UNNAMED to my gradle.properties file. I see the value echoed in the build, but it doesn’t actually get used. I’ve also tried adding the jvmArg to the test block :

test {    
systemProperties =           
 ['spring.config.location' = "file:$projectDir/src/main/config/runtime/local/app/application.properties"]   
jvmArgs = ["--add-opens java.base/java.util=ALL-UNNAMED"]
}

When I try that I get the following error :

Unrecognized option: --add-opens java.base/java.util=ALL-UNNAMED

Error: Could not create the Java Virtual Machine.

Error: A fatal exception has occurred. Program will exit.

Could not create the Java Virtual Machine.

Is there a different way to pass the arg to the JVM VM that Jacoco is using?

0

There are 0 answers