The scalac compiler has special parameters
–javabootclasspath path
Override Java boot classpath.
–javaextdirs path
Override Java extdirs classpath.
You have to pass those parameters from gradle scala plugin using an additionalParameters parameter
this approach does not requires forking
allprojects {
tasks.withType(ScalaCompile) {
if (sourceCompatibility == '1.7') {
scalaCompileOptions.with {
def jdk7rt = new File("$System.env.JAVA7_HOME", "jre/lib/rt.jar").canonicalPath
def jdk7ext = new File("$System.env.JAVA7_HOME", "jre/lib/ext").canonicalPath
additionalParameters = ["-javabootclasspath $jdk7rt".toString(), "-javaextdirs $jdk7ext".toString()]
}
}
}
}
I used this approach on my OS with JVM 1.7 as default for compiling with JDK8 some subprojects that requires javafx8. So it should work in your case.