I have jvm toolchain configured as follows:
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(17))
vendor.set(GRAAL_VM)
}
}
My Gradle config:
However, if I run
When I run nativeRun task, I get:
Execution failed for task ':nativeCompile'.
> Determining GraalVM installation failed with message: 'gu' at '/Users/user/.sdkman/candidates/java/current/bin/gu' tool wasn't found. This probably means that JDK at isn't a GraalVM distribution.
the output of java -version in the project console:
$ java -version
openjdk version "17.0.3" 2022-04-19 LTS
OpenJDK Runtime Environment (build 17.0.3+7-LTS)
OpenJDK 64-Bit Server VM (build 17.0.3+7-LTS, mixed mode, sharing)
an when running nativeCompile task:
> Task :nativeCompile
[native-image-plugin] GraalVM Toolchain detection is disabled
[native-image-plugin] GraalVM location read from environment variable: JAVA_HOME
[native-image-plugin] Native Image executable path: /Users/user/.sdkman/candidates/java/20.0.1-graal/lib/svm/bin/native-image
How should I make the Gradle task honor the JVM toolchain? I do not want to set Graal VM as default in the SDKMAN.
I run nativeRun task from IntelliJ (from Gradle tab).

While you might have configured to use GraalVM for Gradle in IntelliJ, it seems like Gradle isn't picking that up when you run
nativeRun.If you run Gradle from some terminal, the IntelliJ setting doesn't matter at all. The IntelliJ setting is for running Gradle from inside IntelliJ (e.g. when building/running the application).
Environment variables
You can configure environment variables to tell Gradle which JVM to use.
By setting
JAVA_HOME, Gradle should pick up the specified location. If you runexport JAVA_HOME=/path/to/graalvm/installationbefore running Gradle, it should use that installation. This will not affect anything outside the terminal and you would need to set the environment variable again when you want to run Gradle using GraalVM again.Another option is to use
GRAALVM_HOMEAs mentioned by the docs of native-build-tools (assuming you are using that), the native Gradle plugin should respect aGRAALVM_HOMEenvironment variable.You can also persist this environment variable on your system as it will not affect Java applications not looking for GraalVM specifically.
Alternatively, you could try to change the
PATHto include thebindirectory of your GraalVM installation which includes thegubinary:settings.gradle
Gradle also allows specifying the JDK to use for building using the
settings.gradle.For this, you create a
settings.gradlein your project directory and setorg.gradle.java.home:You should also be able to set the
GRAALVM_HOMEthis way: