从Java11迁移到Java17后,Gradle上的GraalVM原生映像构建'nativeCompile'任务失败

g6ll5ycj  于 2023-02-14  发布在  Java
关注(0)|答案(1)|浏览(462)

总之,将Gradle属性(源/目标)和原生GraalVM映像从Java 11迁移到Java 17后,构建任务在Gradle上失败。
这是一个micronaut Java服务,在不透露任何专有代码库详细信息的情况下,我将分享失败的“nativeCompile”任务的Gradle输出的以下部分:

[1/7] Initializing...                                                                                    (8.0s @ 0.36GB)
 Version info: 'GraalVM 22.3.1 Java 17 CE'
 Java version info: '17.0.6+10-jvmci-22.3-b13'
 C compiler: gcc (redhat, aarch64, 8.5.0)
 Garbage collector: Serial GC
 6 user-specific feature(s)
 - com.oracle.svm.thirdparty.gson.GsonFeature
 - io.micronaut.buffer.netty.NettyFeature
 - io.micronaut.configuration.kafka.graal.ChecksumFeature
 - io.micronaut.grpc.server.graalvm.HttpNettyFeature
 - io.micronaut.http.netty.graal.HttpNettyFeature
 - io.micronaut.jackson.JacksonDatabindFeature

Fatal error: ------------------------------------------------------------------------------------------------------------------------
                        0.5s (5.9% of total time) in 12 GCs | Peak RSS: 1.26GB | CPU load: 2.25
========================================================================================================================
java.lang.IllegalAccessError: class io.micronaut.grpc.server.graalvm.HttpNettyFeature (in unnamed module @0x128ca7af) cannot access class com.oracle.svm.core.jdk.SystemPropertiesSupport (in module org.graalvm.nativeimage.builder) because module org.graalvm.nativeimage.builder does not export com.oracle.svm.core.jdk to unnamed module @0x128ca7af
        at io.micronaut.grpc.server.graalvm.HttpNettyFeature.beforeAnalysis(HttpNettyFeature.java:84)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$9(NativeImageGenerator.java:736)
Failed generating 'application' after 8.2s.
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:85)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:736)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:578)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
        at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
Error: Image build request failed with exit status 1

> Task :nativeCompile FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':nativeCompile'.
> Process 'command '/opt/graalvm-ce-java17-22.3.1/bin/native-image'' finished with non-zero exit value 1

我没有使用GraalVM的经验(这是遗留的,我在一个容器中运行nativeCompile,该容器是这样创建的:

docker run -it --entrypoint /bin/bash \
 --mount type=bind,source=<path to service source code>,target=/app \
 --mount type=bind,source=<path to home>.gradle,target=/root/.gradle \
 ghcr.io/graalvm/graalvm-ce:ol8-java17-22.3.1

在此容器上,env详细信息如下所示:

bash-4.4# ./gradlew --version

------------------------------------------------------------
Gradle 7.6
------------------------------------------------------------

Build time:   2022-11-25 13:35:10 UTC
Revision:     daece9dbc5b79370cc8e4fd6fe4b2cd400e150a8

Kotlin:       1.7.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.6 (GraalVM Community 17.0.6+10-jvmci-22.3-b13)
OS:           Linux 5.15.49-linuxkit aarch64

我不知道这里要做什么,想知道是否有一个过时的本地依赖项。我知道我还没有发布我的build.gradle坚果,希望有人能给予我一些指示。

vd2z7a6w

vd2z7a6w1#

修正了这个问题。看起来GraalVM发布的更新必须与旧的次要版本同步使用。我想这是一种保持原生类兼容的方法。
在我的例子中,旧的原生映像、gradle和代码库设置使用的是ol 8-java 11 -22.1.0,我将其全部更新为ol 8-java 17 -23.2.1,这是最新的版本。
但是,GraalVM也发布了ol 8-java 17 -22.1.0,它与旧的次要版本相匹配。

相关问题