Hello!

Just generated a new maven spring boot project on Spring Initializr (https://start.spring.io/) using version 3.0.0, Java 17 and GraalVM Native Support.

Application build natively successfully, however it does not when you run native tests as per informed on Spring Boot Reference Documentation (https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#native-image.testing.with-native-build-tools.maven) as follows:

Command: mvn -PnativeTest test

Log:

[INFO]
[INFO] --- native-maven-plugin:0.9.18:test (native-test) @ demo ---
[INFO] ====================
[INFO] Initializing project: demo
[INFO] ====================
[INFO] Found GraalVM installation from JAVA_HOME variable.
[INFO] Downloaded GraalVM reachability metadata repository from file:/C:/Users/ricsfd/.m2/repository/org/graalvm/buildtools/graalvm-reachability-metadata/0.9.18/graalvm-reachability-metadata-0.9.18-repository.zip
[INFO] [graalvm reachability metadata repository for ch.qos.logback:logback-classic:1.4.5]: Configuration directory not found. Trying latest version.
[INFO] [graalvm reachability metadata repository for ch.qos.logback:logback-classic:1.4.5]: Configuration directory is ch.qos.logback\logback-classic\1.4.1
[INFO] Executing: C:\Program Files\BellSoft\LibericaNIK-Full-22-OpenJDK-17\bin\native-image.cmd @target\tmp\native-image-5826493397404161278.args
========================================================================================================================
GraalVM Native Image: Generating 'native-tests.exe' (executable)...
========================================================================================================================

[1/7] Initializing...                                                                                    (0.0s @ 0.30GB)
Error: Default native-compiler executable 'cl.exe' not found via environment variable PATH
Error: To prevent native-toolchain checking provide command-line option -H:-CheckToolchain
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
------------------------------------------------------------------------------------------------------------------------
                         0.3s (3.2% of total time) in 8 GCs | Peak RSS: 0.65GB | CPU load: 0.47
========================================================================================================================
Failed generating 'native-tests.exe' after 8.3s.
Error: Image build request failed with exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  23.657 s
[INFO] Finished at: 2022-12-22T16:02:23-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.graalvm.buildtools:native-maven-plugin:0.9.18:test (native-test) on project demo: Execution of C:\Program Files\BellSoft\LibericaNIK-Full-22-OpenJDK-17\bin\native-image.cmd @target\tmp\native-image-5826493397404161278.args returned non-zero result -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Java version:

java --version

openjdk 17.0.5 2022-10-18 LTS
OpenJDK Runtime Environment GraalVM 22.3.0 (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM GraalVM 22.3.0 (build 17.0.5+8-LTS, mixed mode, sharing)

Maven version:

mvn --version

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: C:\Users\ricsfd\apache-maven-3.8.6
Java version: 17.0.5, vendor: BellSoft, runtime: C:\Program Files\BellSoft\LibericaNIK-Full-22-OpenJDK-17
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Is this a known behavior/bug?

Thanks in advance.

Comment From: scottfrederick

This appears to be caused by some missing requirements for running the GraalVM native-image tooling (which is used by the native-maven-plugin that is generating the error here) on Windows. There are some prerequisites listed in the section Prerequisites for Using Native Image on Windows in the Native Image documentation. There is also some good information in a StackOverflow post.

Can you try the steps mentioned on those sources and let us know if that fixes the problem?

Comment From: trcoelho

Hi, thanks for reply.

Have tried mentioned configuration on StackOverflow post, as said, set GRAALVM_HOME to located native-image.cmd as follows:

echo $Env:GRAALVM_HOME

C:\Program Files\BellSoft\LibericaNIK-Full-22-OpenJDK-17\bin\native-image.cmd

And still got same output:

[INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.graalvm.buildtools:native-maven-plugin:0.9.18:test (native-test) on project demo: Execution of C:\Program Files\BellSoft\LibericaNIK-Full-22-OpenJDK-17\bin\native-image.cmd @target\tmp\native-image-3540024246537322683.args returned non-zero result -> [Help 1]

Also I have tried same scenario on a Ubuntu 22.04.1 LTS and got same behavior. Am using Native Image Kit from Bellsoft (Liberica Full 11.0.17+7 x86 64 for Windows) downloaded on

https://bell-sw.com/pages/downloads/native-image-kit/

NIK 22 (JDK 17).

By the way, it only happens when run:

mvn -PnativeTest test

Do you have success if you configure a project using spring initialzr project and try to run exactly same scenario? Do I need download and install GraalVM (https://www.graalvm.org/)?

Thanks in advance.

Comment From: scottfrederick

Do you have success if you configure a project using spring initialzr project and try to run exactly same scenario?

Yes, as have many people on the Spring team, mostly on macOS, some on Ubuntu and Fedora, and a few on Windows.

By the way, it only happens when run: mvn -PnativeTest test

Can you explain more about this? Are you saying that this doesn't happen when you run mvn -Pnative native:compile? Can you successfully build the sample shown on this page after following those setup instructions?

Comment From: trcoelho

Hi @scottfrederick , sorry for delayed response.

Have followed what you suggested (https://medium.com/graalvm/using-graalvm-and-native-image-on-windows-10-9954dc071311) and now I could run mvn -PnativeTest test command successfully!

This command should be done on x64 Native Tools Command Prompt for VS 2019 command prompt when MVSC is installed as per your comment above.

For whom facing same behavior:

  1. Download GraalVM (https://github.com/graalvm/graalvm-ce-builds/releases/tag/vm-22.3.0).
  2. Unzip downloaded file.
  3. Set environment variables as follows: GRAALVM_HOME=unzipped graalvm path JAVA_HOME=unzipped graalvm path Also add bin paths to 'Path' variable as follows: %GRAALVM_HOME%\bin %JAVA_HOME%\bin
  4. Download Visual Studio Build Tools (https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16)
  5. Windows SDK 11
  6. Opened x64 Native Tools Command Prompt for VS 2019, go to maven project root folder and run mvn -PnativeTest test.

Really appreciate your support!