Skip to content

Commit 5eb9c5f

Browse files
committed
Fix regression: restore binary javaLauncher convention for toolchain detection
The previous change removed the per-binary javaLauncher convention wiring (nativeImages.configureEach(options -> options.getJavaLauncher().convention(defaultJavaLauncher))), breaking graalvmNative.binaries.main.javaLauncher resolution and NativeImageOptionsTest ('toolchain defaults to the current Java version'). Restore the convention and resolve defaultJavaLauncher directly to the toolchain launcher when toolchain detection is enabled. Whether the toolchain actually contains native-image is decided at build time by NativeImageExecutableLocator, which falls back to GRAALVM_HOME — so the convention stays queryable while the explicit-vs-convention launcher feature is preserved.
1 parent 5e239e2 commit 5eb9c5f

1 file changed

Lines changed: 10 additions & 21 deletions

File tree

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/DefaultGraalVmExtension.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@
6363

6464
import java.io.File;
6565

66-
import static org.graalvm.buildtools.utils.SharedConstants.NATIVE_IMAGE_EXE;
67-
6866
public abstract class DefaultGraalVmExtension implements GraalVMExtension {
6967
private final transient NamedDomainObjectContainer<NativeImageOptions> nativeImages;
7068
private final transient NativeImagePlugin plugin;
@@ -80,6 +78,9 @@ public DefaultGraalVmExtension(NamedDomainObjectContainer<NativeImageOptions> na
8078
this.project = project;
8179
this.defaultJavaLauncher = project.getObjects().property(JavaLauncher.class);
8280
getToolchainDetection().convention(false);
81+
// Every binary exposes a javaLauncher convention so graalvmNative.binaries.main.javaLauncher
82+
// is always resolvable (e.g. its metadata.languageVersion) when toolchain detection is on. §FS-native-invocation.1.5
83+
nativeImages.configureEach(options -> options.getJavaLauncher().convention(defaultJavaLauncher));
8384
getTestSupport().convention(true);
8485
AgentOptions agentOpts = getAgent();
8586
agentOpts.getDefaultMode().convention("standard");
@@ -108,26 +109,14 @@ private void configureToolchain() {
108109
if (toolchainService == null) {
109110
return null;
110111
}
111-
// Probe the resolved toolchain for native-image before using it.
112-
// If native-image is absent, return null so the native-image locator
113-
// falls back to the Gradle JVM (java.home) per §FS-native-invocation.1.5.
112+
// Resolve the toolchain launcher for the configured Java toolchain.
113+
// This keeps graalvmNative.binaries.main.javaLauncher queryable (e.g. its
114+
// metadata.languageVersion) whenever toolchain detection is enabled.
115+
// Whether the toolchain actually contains native-image is decided at build
116+
// time by NativeImageExecutableLocator, which falls back to GRAALVM_HOME
117+
// when the launcher's installation lacks it. §FS-native-invocation.1.5
114118
JavaPluginExtension javaConvention = project.getExtensions().getByType(JavaPluginExtension.class);
115-
Provider<JavaLauncher> javaToolchainLauncher = toolchainService.launcherFor(javaConvention.getToolchain());
116-
// Verify toolchain contains native-image by probing it
117-
Provider<JavaLauncher> probeResult = javaToolchainLauncher.map(l -> {
118-
try {
119-
File nativeImage = l.getMetadata().getInstallationPath().file("bin/" + NATIVE_IMAGE_EXE).getAsFile();
120-
if (nativeImage.exists()) {
121-
return l;
122-
}
123-
// native-image not found; return null so the locator falls back to the Gradle JVM (java.home)
124-
return null;
125-
} catch (Exception e) {
126-
// Probe failed; return null so the locator falls back to the Gradle JVM (java.home)
127-
return null;
128-
}
129-
});
130-
return probeResult;
119+
return toolchainService.launcherFor(javaConvention.getToolchain());
131120
})
132121
);
133122
}

0 commit comments

Comments
 (0)