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 <[email protected]>
Цей коміт міститься в:
Vadim LazukтаInf1mum authored and GitHub committed 2026-11-25 02:19:25 +08:00
1 джерело cd3399df60
коміт 63f2f0280d
2 files changed
+12

No files matched your search

+5
Переглянути файл
@@ -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')
+7
Переглянути файл
@@ -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", () => {