简体   繁体   English

Spring 本机启动:没有有效的 native-image-svm 依赖项

[英]Spring Boot Native: no valid dependencies for native-image-svm

I've just upgraded several projects to Java 19, Spring Boot 3.0.2, Kotlin 1.8.0 with Maven and I'd like Spring Boot to generate native images.我刚刚将几个项目升级到 Java 19、Spring Boot 3.0.2、Kotlin 1.8.0 和 Maven,我想要 Spring Boot 生成本机图像。

<java.version>19</java.version>
<kotlin.version>1.8.0</kotlin.version>

The relevant part of the configuration of spring-boot-maven-plugin is: spring-boot-maven-plugin配置的相关部分是:

        <configuration>
          <image>
            <env>
              <BP_JVM_VERSION>19.*</BP_JVM_VERSION>
              <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
              <BPE_APPEND_JAVA_TOOL_OPTIONS>-XX:+HeapDumpOnOutOfMemoryError -XX:MaxDirectMemorySize=64M</BPE_APPEND_JAVA_TOOL_OPTIONS>
              <BPE_DELIM_JAVA_TOOL_OPTIONS xml:space="preserve"> </BPE_DELIM_JAVA_TOOL_OPTIONS>
            </env>
          </image>
        </configuration>

However, when I build one of the projects with但是,当我构建其中一个项目时

mvn -Pnative spring-boot:build-image

then the build fails with the following error message:然后构建失败并显示以下错误消息:

[INFO]     [creator]     Paketo Buildpack for BellSoft Liberica 9.10.2
[INFO]     [creator]       unable to find dependency
[INFO]     [creator]       no valid dependencies for native-image-svm, 19.*, and io.paketo.stacks.tiny in [(jdk, 8.0.362, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jre, 8.0.362, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jdk, 11.0.18, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jre, 11.0.18, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (native-image-svm, 11.0.17, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jdk, 17.0.6, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jre, 17.0.6, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (native-image-svm, 17.0.5, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jdk, 19.0.2, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jre, 19.0.2, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *])]
[INFO]     [creator]     ERROR: failed to build: exit status 1

What's missing?缺少了什么?

Update: When I downgrade to Java 17 with Kotlin 1.7.21, then the build succeeds and apparently there's no support yet in the Liberica Native Image Kit for Java 19. https://bell-sw.com/pages/downloads/native-image-kit/#/nik-22-19更新:当我使用 Kotlin 1.7.21 降级到 Java 17 时,构建成功,显然 Liberica Native Image Kit 中还没有支持 Java 19. https://bell-sw.com/pages/downloads/native-图像套件/#/nik-22-19

Let me provide you with alternatives to downgrading your Java version (in case you eg want to use virtual threads).让我为您提供降级 Java 版本的替代方案(以防您想要使用虚拟线程)。

You might be successful using GraalVM instead of Liberica NIK.您可能会成功使用 GraalVM 而不是 Liberica NIK。 You can configure this in your pom.xml as described in the section Use an alternative native image toolkit of the Spring Boot Documentation:您可以在pom.xml中配置它,如 Spring 引导文档Use an alternative native image toolkit部分所述:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <image>
            <buildpacks>
                <buildpack>gcr.io/paketo-buildpacks/graalvm</buildpack>
                <buildpack>gcr.io/paketo-buildpacks/java-native-image</buildpack>
            </buildpacks>
        </image>
    </configuration>
</plugin>

Since The GraalVM Buildpack supports Java 19 , you should be able to use it:由于GraalVM Buildpack 支持 Java 19 ,您应该可以使用它:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <image>
            <buildpacks>
                <buildpack>gcr.io/paketo-buildpacks/graalvm</buildpack>
                <buildpack>gcr.io/paketo-buildpacks/java-native-image</buildpack>
            </buildpacks>
            <env>
                <BP_JVM_VERSION>19.0.1</BP_JVM_VERSION>
            </env>
        </image>
    </configuration>
</plugin>

As an alternative, it would be possible to not use buildpacks for creating the native image but instead create a native executable using mvn -Pnative package See Getting started with Native Build Tools .作为替代方案,可以不使用 buildpack 来创建本机映像,而是使用mvn -Pnative package创建本机可执行文件,请参阅本机构建工具入门

Then, you could create your own docker image (eg using a Dockerfile or similar) and include that.然后,您可以创建自己的 docker 图像(例如使用Dockerfile或类似图像)并包含它。

When I downgrade to Java 17 with Kotlin 1.7.21, then the build succeeds and apparently there's no support yet in the Liberica Native Image Kit for Java 19. https://bell-sw.com/pages/downloads/native-image-kit/#/nik-22-19 .当我使用 Kotlin 1.7.21 降级到 Java 17 时,构建成功,显然 Liberica Native Image Kit 中还没有支持 Java 19. https://bell-sw.com/pages/downloads/native-image-套件/#/nik-22-19

Furthermore, it's stated on the same page:此外,它在同一页上说明:

  1. What Java versions are supported by NIK? NIK 支持哪些 Java 版本?

Two latest Java LTS versions, Java 11 and Java 17, are supported by Liberica NIK. Liberica NIK 支持两个最新的 Java LTS 版本,Java 11 和 Java 17。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM