Gradle Compiler Daemon jvm opts [solved]


(Thibault Kruse) #1

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.


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: https://builds.gradle.org/project.html?projectId=Gradle_Master_CoveragePhase_LinuxCoverage_LinuxJava19&tab=projectOverview

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/com.sun.tools.javac.api=ALL-UNNAMED'
  }
  tasks.withType(GroovyCompile) {
    options.fork = true
    options.forkOptions.jvmArgs << '-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED'
  }
}