How do I specify a different jvm per module with the groovy plugin (instructions do not seem to work)

plugins

(Alasdair Richardson) #1

I have a Groovy project which is mostly built using Java 7, but I want to build one module using Java 8. To investigate why it did not seem to work when following the plugin instructions for doing this I created a project with 3 modules, one using java 7, one java 8, and the third was groovy requiring java8, each with one class. As suggested in the plugin documents I have added the following to the build files for the 2 projects requiring java 8:

sourceCompatibility = 1.8
tasks.withType(AbstractCompile) {
    options.fork([javaHome: file('/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home')])
    println 'COMPILE TASK ' + project + ':' + name + ': ' + options.fork + ' - ' + 
    options.forkOptions.javaHome
}

and in the top level (just for checking) I added

gradle.taskGraph.beforeTask { Task task ->
    if (task.name.contains('compile')) {
        println '**************** RUN COMPILE TASK ' + task.project + ':' + task.name + ': ' + task.options.fork + ' - ' + task.options.forkOptions.javaHome
    }
}

Now I see the expected output when gradle is creating the tasks, and you can see the output when running the tasks in the log entries below.

What happens is the java-8 module works fine, it forks a process using java 8 and compiles no problem. However the groovy-java-8 module does not. It seems to start a worker daemon with java 7 and try compiling in that. So my question is - what am I doing wrong?

Below are what I believe to be the relevant log lines (with debug)

=== THIS IS THE JAVA ONE (WORKS) ===

11:32:18.538 [QUIET] [system.out] **************** RUN COMPILE TASK project ':java-8':compileJava: true - /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
11:32:18.538 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Starting to execute task ':java-8:compileJava' 
11:32:18.540 [INFO] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Putting task artifact state for task ':java-8:compileJava' into context took 0.002 secs.

11:32:18.543 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java''. Working directory: /Users/alasdair/workspace/test-project Command: /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java -version
...

11:32:18.649 [DEBUG] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Determining if task ':java-8:compileJava' is up-to-date
11:32:18.649 [INFO] [org.gradle.api.internal.changedetection.rules.TaskTypeTaskStateChanges] Task :java-8:compileJava class loader hash: 30c2a81bd6e2d5925528e170cc328c90
11:32:18.649 [INFO] [org.gradle.api.internal.changedetection.rules.TaskTypeTaskStateChanges] Task :java-8:compileJava actions class loader hashes: [7c8fa27d1d194f040370d9584b8177bc,30c2a81bd6e2d5925528e170cc328c90]
11:32:18.655 [INFO] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Executing task ':java-8:compileJava' (up-to-date check took 0.006 secs) due to:
Input property 'source' file /Users/alasdair/workspace/test-project/java-8/src/main/java/Foo.java has changed.
11:32:18.656 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':java-8:compileJava'.
11:32:18.659 [DEBUG] [org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler] Compiler arguments: -source 1.8 -target 1.8 -d /Users/alasdair/workspace/test-project/java-8/build/classes/main -g -sourcepath  -proc:none -XDuseUnsharedTable=true -classpath  /Users/alasdair/workspace/test-project/java-8/src/main/java/Foo.java
11:32:18.659 [INFO] [org.gradle.api.internal.tasks.compile.CommandLineJavaCompiler] Compiling with Java command line compiler '/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/javac'.
11:32:18.663 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/javac''. Working directory: /Users/alasdair/workspace/test-project/java-8 Command: /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/javac @/Users/alasdair/workspace/test-project/java-8/build/tmp/compileJava/java-compiler-args.txt

=== THIS IS THE GROOVY ONE (NOT WORKING) ===

11:32:16.881 [QUIET] [system.out] **************** RUN COMPILE TASK project ':groovy-java-8':compileGroovy: true - /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
11:32:16.881 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Starting to execute task ':groovy-java-8:compileGroovy'
11:32:16.884 [INFO] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Putting task artifact state for task ':groovy-java-8:compileGroovy' into context took 0.003 secs.

11:32:16.887 [DEBUG] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Determining if task ':groovy-java-8:compileGroovy' is up-to-date
11:32:16.889 [INFO] [org.gradle.api.internal.changedetection.rules.TaskTypeTaskStateChanges] Task :groovy-java-8:compileGroovy class loader hash: 30c2a81bd6e2d5925528e170cc328c90
11:32:16.889 [INFO] [org.gradle.api.internal.changedetection.rules.TaskTypeTaskStateChanges] Task :groovy-java-8:compileGroovy actions class loader hashes: [7c8fa27d1d194f040370d9584b8177bc, 30c2a81bd6e2d5925528e170cc328c90]
11:32:16.994 [INFO] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Executing task ':groovy-java-8:compileGroovy' (up-to-date check took 0.107 secs) due to:
Output property 'destinationDir' file /Users/alasdair/workspace/test-project/groovy-java-8/build/classes/main/Foo.class has been removed.
11:32:16.994 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':groovy-java-8:compileGroovy'.

11:32:17.010 [DEBUG] [org.gradle.api.internal.tasks.compile.NormalizingGroovyCompiler] Java compiler arguments: -source 1.8 -target 1.8 -d /Users/alasdair/workspace/test-project/groovy-java-8/build/classes/main -g -sourcepath  -proc:none -XDuseUnsharedTable=true -classpath /Users/alasdair/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.3.11/f6b34997d04c1538ce451d3955298f46fdb4dbd4/groovy-all-2.3.11.jar:/Users/alasdair/workspace/test-project/groovy-java-8/build/classes/main /Users/alasdair/workspace/test-project/groovy-java-8/src/main/groovy/Foo.groovy
11:32:17.013 [DEBUG] [org.gradle.workers.internal.WorkerDaemonStarter] Starting Gradle worker daemon with fork options DaemonForkOptions{minHeapSize=null, maxHeapSize=null, jvmArgs=[], classpath=[/Users/alasdair/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.3.11/f6b34997d04c1538ce451d3955298f46fdb4dbd4/groovy-all-2.3.11.jar, /Users/alasdair/.gradle/wrapper/dists/gradle-3.5-rc-2-bin/7ktl4k9rdug30mawecgppf5ms/gradle-3.5-rc-2/lib/ant-1.9.6.jar, /Users/alasdair/.gradle/wrapper/dists/gradle-3.5-rc-2-bin/7ktl4k9rdug30mawecgppf5ms/gradle-3.5-rc-2/lib/ant-launcher-1.9.6.jar]}.
11:32:17.030 [DEBUG] [org.gradle.internal.remote.internal.inet.TcpIncomingConnector] Listening on [a769f284-7758-47fa-aa20-615451fa5440 port:55731, addresses:[/0:0:0:0:0:0:0:1, /127.0.0.1]].
11:32:17.031 [DEBUG] [org.gradle.process.internal.worker.DefaultWorkerProcessBuilder] Creating Gradle Worker Daemon 1
11:32:17.031 [DEBUG] [org.gradle.process.internal.worker.DefaultWorkerProcessBuilder] Using application classpath [/Users/alasdair/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.3.11/f6b34997d04c1538ce451d3955298f46fdb4dbd4/groovy-all-2.3.11.jar, /Users/alasdair/.gradle/wrapper/dists/gradle-3.5-rc-2-bin/7ktl4k9rdug30mawecgppf5ms/gradle-3.5-rc-2/lib/ant-1.9.6.jar, /Users/alasdair/.gradle/wrapper/dists/gradle-3.5-rc-2-bin/7ktl4k9rdug30mawecgppf5ms/gradle-3.5-rc-2/lib/ant-launcher-1.9.6.jar]
11:32:17.037 [DEBUG] [org.gradle.process.internal.worker.child.WorkerProcessClassPathProvider] Using worker process classpath: [/Users/alasdair/.gradle/caches/3.5-rc-2/workerMain/gradle-worker.jar]
11:32:17.059 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'Gradle Worker Daemon 1'. Working directory: /Users/alasdair/workspace/test-project Command: /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/bin/java -Djava.security.manager=worker.org.gradle.process.internal.worker.child.BootstrapSecurityManager -Dfile.encoding=UTF-8 -Duser.country=GB -Duser.language=en -Duser.variant -cp /Users/alasdair/.gradle/caches/3.5-rc-2/workerMain/gradle-worker.jar worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Worker Daemon 1'
11:32:17.060 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING