From 7c206893b0e40a1f3d558ed186f09b539112759b Mon Sep 17 00:00:00 2001 From: Santiago Mola Date: Fri, 17 Jan 2025 16:51:45 +0100 Subject: [PATCH] Fix setJavaVersion for groovy --- gradle/java_no_deps.gradle | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/gradle/java_no_deps.gradle b/gradle/java_no_deps.gradle index ab643009662..8f130dd015d 100644 --- a/gradle/java_no_deps.gradle +++ b/gradle/java_no_deps.gradle @@ -74,17 +74,23 @@ ext.setJavaVersion = (it, javaVersionInteger) -> { Provider compiler = javaToolchains.compilerFor { languageVersion = JavaLanguageVersion.of(javaVersionInteger) } + Provider 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?") }