GraalVM原生镜像与Micronaut和AWS SDK v2。

huangapple go评论63阅读模式
英文:

GraalVM native image with micronaut and aws sdk-v2

问题

我在使用 Micronaut 和 AWS SDK v2 构建 GraalVM 本地镜像时遇到了问题。在详细说明错误之前,我想指出在使用 sdk-v2 之前,本地镜像是可以正常构建的。

一旦我更新到 aws sdk-v2(通过 Micronaut 依赖),如下所示:

...
implementation "io.micronaut.aws:micronaut-aws-sdk-v2:2.0.2"
...

当尝试构建镜像时,出现错误:

致命错误: java.lang.NoSuchMethodError
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	...
Caused by: java.lang.NoSuchMethodError: 'void io.micronaut.core.graal.AutomaticFeatureUtils.initializeAtBuildTime(org.graalvm.nativeimage.hosted.Feature$BeforeAnalysisAccess, java.lang.String)'
	at io.micronaut.aws.sdk.v2.graal.AwsSdkAutomaticFeature.beforeAnalysis(AwsSdkAutomaticFeature.java:41)
	...
Error: Image build request failed with exit status 1
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
	...

我的假设是 Micronaut 可能在内部进行了一些反射操作,这导致构建过程失败。我已经添加了以下 JSON 文件来设置反射配置:

[
  {
    "name": "io.micronaut.core.graal.AutomaticFeatureUtils",
    "allDeclaredConstructors": true,
    "allPublicConstructors": true,
    "allDeclaredMethods": true,
    "allPublicMethods": true
  },
  {
    "name": "io.micronaut.core.graal.AutomaticFeatureUtils",
    "methods": [
      {
        "name": "initializeAtBuildTime",
        "parameterTypes": ["org.graalvm.nativeimage.hosted.Feature$BeforeAnalysisAccess", "java.lang.String[]"]
      }
    ]
  }
]

然而,错误仍然存在。我不确定是否是因为 AutomaticFeatureUtils.initializeAtBuildTime 方法期望一个字符串的可变参数数组,但是在堆栈跟踪中我只看到一个字符串被传递,或者错误与反射无关。

无论我尝试什么,构建镜像时都无法找到那个方法。

你对我可能漏掉了什么有什么想法吗?

谢谢!

英文:

I have an issue when building a GraalVM native image using micronaut and aws sdk-v2. Before detailing the error I want to note that before using the sdk-v2 the native image was built correctly.

Once I updated to aws sdk-v2 (via micronaut dependency as):

...
implementation "io.micronaut.aws:micronaut-aws-sdk-v2:2.0.2"
...

I get an error when the trying to built the image

Fatal error:java.lang.NoSuchMethodError
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:603)
	at java.base/java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1006)
	at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:480)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:349)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:508)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:114)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:537)
Caused by: java.lang.NoSuchMethodError: 'void io.micronaut.core.graal.AutomaticFeatureUtils.initializeAtBuildTime(org.graalvm.nativeimage.hosted.Feature$BeforeAnalysisAccess, java.lang.String)'
	at io.micronaut.aws.sdk.v2.graal.AwsSdkAutomaticFeature.beforeAnalysis(AwsSdkAutomaticFeature.java:41)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$7(NativeImageGenerator.java:693)
	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:70)
	at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:693)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:555)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:468)
	at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Error: Image build request failed with exit status 1
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
	at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1558)
	at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1308)
	at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1269)
	at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1228)
	at com.oracle.svm.driver.NativeImage$JDK9Plus.main(NativeImage.java:1740)
...

My assumption was that micronaut must be doing some reflection internally and that is making the build process to fail.
I have added the following json file to set a reflection configuartion

[
  {
    "name" : "io.micronaut.core.graal.AutomaticFeatureUtils",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true
  },
  {
    "name":"io.micronaut.core.graal.AutomaticFeatureUtils",
    "methods":[{"name":"initializeAtBuildTime","parameterTypes":["org.graalvm.nativeimage.hosted.Feature$BeforeAnalysisAccess","java.lang.String[]"] }]
  }
]

However the error persists. Not sure if it is due to the fact that AutomaticFeatureUtils.initializeAtBuildTime is expecting a varargs of strings and however in the stacktrace I can see just one String being passed, or the error is not related to reflection at all.

No matter what I try, that method is not found when building the image.

Any idea on what I may be missing here?

Thanks!!

答案1

得分: 1

这个错误与反射无关。

Feature 和 AutomaticFeature 是 GraalVM 本机映像的概念,允许对本机映像进行编程配置,更多细节可以在 javadoc 中找到:https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/Feature.java#L59

您展示的错误发生在图像生成过程中,这是一个正常的 Java 进程,不需要配置反射等。这些是运行时行为的配置。

错误信息表示 AwsSdkAutomaticFeature来源)尝试调用 void io.micronaut.core.graal.AutomaticFeatureUtils.initializeAtBuildTime(org.graalvm.nativeimage.hosted.Feature$BeforeAnalysisAccess, java.lang.String),但没有这样的方法。最可能的原因是依赖项与包含 graal 支持 的核心 Micronaut 库之间的版本不匹配

英文:

This error is not related to reflection.

Feature and AutomaticFeature are GraalVM native image concepts that allow programmatic configuration for the native iamge, more details can be found for example in the javadoc: https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/Feature.java#L59

The error you show happens during the image generation, this is a normal java process, which doesn't need to have reflection configured etc. Those are the configuration for the runtime behavior.

What the error says is that AwsSdkAutomaticFeature (source tries to call void io.micronaut.core.graal.AutomaticFeatureUtils.initializeAtBuildTime(org.graalvm.nativeimage.hosted.Feature$BeforeAnalysisAccess, java.lang.String) but there's no such method. Most probable cause is the version mismatch between the dependency and the core micronaut library that contain graal support.

huangapple
  • 本文由 发表于 2020年9月21日 19:14:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63991147.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定