nativeCompile task fails gu tool wasn't found even if vendor set to Graal VM

1.1k views Asked by At

I have jvm toolchain configured as follows:

kotlin {
    jvmToolchain {
        languageVersion.set(JavaLanguageVersion.of(17))
        vendor.set(GRAAL_VM)
    }
}

My Gradle config:

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).

1

There are 1 answers

5
dan1st might be happy again On

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 run export JAVA_HOME=/path/to/graalvm/installation before 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_HOME As mentioned by the docs of native-build-tools (assuming you are using that), the native Gradle plugin should respect a GRAALVM_HOME environment variable.

export JAVA_HOME=/path/to/graalvm/installation

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 PATH to include the bin directory of your GraalVM installation which includes the gu binary:

export PATH=/path/to/graalvm/installation/bin:$PATH

settings.gradle

Gradle also allows specifying the JDK to use for building using the settings.gradle.

For this, you create a settings.gradle in your project directory and set org.gradle.java.home:

# inside the settings.gradle
org.gradle.java.home=/path/to/graalvm/installation

You should also be able to set the GRAALVM_HOME this way:

# inside the settings.gradle
org.gradle.project.GRAALVM_HOME=/path/to/graalvm/installation