Hi,
trying to build Groovy using Gradle on JDK9, I stumbed upon a similar problem as other users:
I am aware of https://github.com/gradle/gradle/blob/master/design-docs/jdk9-support.md
The symptom:
gradle test -Pindy=true --info --stacktrace --tests org.codehaus.groovy.tools.shell.completion.Groovy* --console=plain --no-daemon --max-workers=1
...
Starting process 'Gradle Compiler Daemon 1'. Working directory: ...
Command: .../jdk-9/bin/java @/tmp/gradle-worker-classpath602146501273645541txt -Xmx384m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant jarjar.org.gradle.process.internal.launcher.GradleWorkerMain 'Gradle Compiler Daemon 1'
....
FAILURE: Build failed with an exception.
...
Caused by: java.lang.IllegalAccessException: class org.gradle.internal.reflect.DirectInstantiator cannot access class com.sun.tools.javac.api.JavacTool (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.api to unnamed module @18408763
Now I tried to set
-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
using various ways, JAVA_OTPS, GRADLE_OPTS, DEFAULT_JVM_OPTS, gradle.properties/org.gradle.jvmargs, even options.compilerArgs. None of it had any impact on the compile failure. I believe the reason is that gradle spawns a compiler daemon without taking into account any of those jvm option locations (See log output line “Command:”).
So the only way I found to get that option in there was to create a custom java executable like this:
#! /usr/bin/env bash
/path/to/real/java -XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED $*
That way, the compile process finally took into account the exported package.
It would be nice if there was a better solution for this. Not just for this specific option, but for any use-case where the jvm options of the compiler daemon have to be adjusted.