Gradle Compiler Daemon jvm opts [solved]

(Thibault Kruse) #1

trying to build Groovy using Gradle on JDK9, I stumbed upon a similar problem as other users:

I am aware of

The symptom:

gradle test -Pindy=true --info --stacktrace --tests* --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.language=en -Duser.variant 'Gradle Compiler Daemon 1'
FAILURE: Build failed with an exception.
Caused by: java.lang.IllegalAccessException: class org.gradle.internal.reflect.DirectInstantiator cannot access class (in module jdk.compiler) because module jdk.compiler does not export to unnamed module @18408763

Now I tried to set


using various ways, JAVA_OTPS, GRADLE_OPTS, DEFAULT_JVM_OPTS,, 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/ $*

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.

JDK9 Jigsaw build problem
Gradle 2.12 fails to build when running on JDK 9
(Sterling Greene) #2

I don’t have Java 9 to try on this computer. Have you tried something like

apply plugin: 'java'

compileJava {
   options.fork = true
   options.forkOptions.jvmArgs << '-showversion'

We’re working on JDK9 support right now. Here’s our CI builds:

The recent class file version change is going to break a lot of things (e.g., ASM5 doesn’t support the new version, so we’re having to work around it).

(Thibault Kruse) #3

That helped me get it work. Actually I did this now, because javaCompile and groovyCompile launch different daemons:

// In root build.gradle
allprojects {
  tasks.withType(JavaCompile) {
    options.fork = true
    options.forkOptions.jvmArgs << '-XaddExports:jdk.compiler/'
  tasks.withType(GroovyCompile) {
    options.fork = true
    options.forkOptions.jvmArgs << '-XaddExports:jdk.compiler/'