Skip to content

Commit

Permalink
Fix setJavaVersion for groovy
Browse files Browse the repository at this point in the history
  • Loading branch information
smola committed Jan 17, 2025
1 parent 1da8e12 commit 7c20689
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions gradle/java_no_deps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,23 @@ ext.setJavaVersion = (it, javaVersionInteger) -> {
Provider<JavaCompiler> compiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(javaVersionInteger)
}
Provider<JavaLauncher> launcher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(javaVersionInteger)
}
try {
//ac.configure {
it.options.fork = true
if (it.hasProperty('javaCompiler')) {
// Works for JavaCompile
it.javaCompiler = compiler
if (it instanceof JavaCompile) {
JavaCompile jc = (JavaCompile) it
jc.javaCompiler = compiler
} else if (it instanceof GroovyCompile) {
GroovyCompile gc = (GroovyCompile) it
gc.javaLauncher = launcher
} else if (it instanceof ScalaCompile) {
ScalaCompile sc = (ScalaCompile) it
sc.javaLauncher = launcher
} else {
// Works for GroovyCompile and ScalaCompile
it.options.forkOptions.javaHome = compiler.get().metadata.installationPath.asFile
throw new GradleException("Unsupported compile type: ${it.getClass()}")
}
//}
} catch (NoSuchElementException ignored) {
throw new GradleException("Unable to find compiler for Java $javaVersionInteger. Have you set JAVA_${javaVersionInteger}_HOME?")
}
Expand Down

0 comments on commit 7c20689

Please sign in to comment.