From 63f2f0280d4afd44a99ea5df3a02085eb6cadd9e Mon Sep 17 00:00:00 2001 From: Vadim Lazuk Date: Tue, 24 Nov 2026 21:19:25 +0300 Subject: [PATCH] fix(run): launch a Gradle-delegated run on the project's Java toolchain (#5656) Build and run using Gradle started the main class on Gradle's own JVM: the openideaRun JavaExec task never set javaLauncher, and before Gradle 9 JavaExec does not default to the project's toolchain. With a toolchain newer than Gradle's JVM the class failed with UnsupportedClassVersionError. On Gradle 6.7+ the task now launches on the project's Java toolchain, as the application plugin's run does; a project without a toolchain still runs on Gradle's JVM. Fixes #5594 Co-authored-by: Inf1mum <8135225+Inf1mum@users.noreply.github.com> --- src/features/run/gradleRun.gradle | 5 +++++ src/features/run/gradleRun.test.ts | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/features/run/gradleRun.gradle b/src/features/run/gradleRun.gradle index 7c41b06114..8e0772aaad 100644 --- a/src/features/run/gradleRun.gradle +++ b/src/features/run/gradleRun.gradle @@ -21,6 +21,11 @@ allprojects { p -> t.classpath = p.sourceSets.getByName(System.getProperty('openidea.run.sourceSet', 'main')).runtimeClasspath def main = System.getProperty('openidea.run.main') if (t.hasProperty('mainClass')) t.mainClass.set(main) else t.main = main + // Gradle 6.7+: the project's Java toolchain launches it, as the application plugin's `run` does. + if (t.hasProperty('javaLauncher')) { + def java = p.extensions.getByType(org.gradle.api.plugins.JavaPluginExtension) + t.javaLauncher.set(p.extensions.getByType(org.gradle.jvm.toolchain.JavaToolchainService).launcherFor(java.toolchain)) + } t.args(list('openidea.run.args')) t.jvmArgs(list('openidea.run.jvmArgs')) def token = System.getProperty('openidea.run.token') diff --git a/src/features/run/gradleRun.test.ts b/src/features/run/gradleRun.test.ts index 0e64cf95a0..903c5da0a7 100644 --- a/src/features/run/gradleRun.test.ts +++ b/src/features/run/gradleRun.test.ts @@ -274,6 +274,13 @@ describe("Build and run using: Gradle", () => { expect(RUN_SCRIPT).toContain("else p.tasks.create('openideaRun', JavaExec, configure)"); expect(RUN_SCRIPT).toContain("import org.gradle.util.GradleVersion"); }); + + // A toolchain newer than Gradle's JVM: on it, a class compiled for that toolchain fails to load (#5594). + it("launches on the project's Java toolchain, as the application plugin's `run` does (#5594)", () => { + // `javaLauncher` is Gradle 6.7+: guarded on its line, like `mainClass`. + expect(RUN_SCRIPT).toContain("if (t.hasProperty('javaLauncher'))"); + expect(RUN_SCRIPT).toContain("JavaToolchainService).launcherFor("); + }); }); describe("Gradle test runs", () => {