当我根据 Micronaut documentation 将我的应用程序打包为 native 镜像时,使用 Java 11.0.9 (GraalVM CE 20.3.0) 和 Micronaut 2.2.1 应用程序利用 Firebase admin 7.1.0 ,我收到以下错误:
$ ./gradlew nativeImage
> Task :nativeImage
[application:15026] classlist: 4,054.46 ms, 1.19 GB
[application:15026] (cap): 504.32 ms, 1.19 GB
[application:15026] setup: 1,827.02 ms, 1.19 GB
To see how the classes got initialized, use --trace-class-initialization=org.conscrypt.Conscrypt,org.conscrypt.OpenSSLProvider
[application:15026] analysis: 29,787.52 ms, 3.90 GB
Error: Classes that should be initialized at run time got initialized during image building:
org.conscrypt.Conscrypt was unintentionally initialized at build time. To see why org.conscrypt.Conscrypt got initialized use --trace-class-initialization=org.conscrypt.Conscrypt
org.conscrypt.OpenSSLProvider was unintentionally initialized at build time. To see why org.conscrypt.OpenSSLProvider got initialized use --trace-class-initialization=org.conscrypt.OpenSSLProvider
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1
> Task :nativeImage FAILED
FAILURE: Build failed with an exception.
该问题是由包 org.conscrypt
中的类引起的.相关的依赖来自com.google.cloud:google-cloud-firestore:1.35.0
获取 org.conscrypt:conscrypt-openjdk-uber:2.2.1
.我对 GraalVM 真的很陌生,并且远未了解导致此类问题的原因。但是,我注意到应该可以传递给
native-image
一些参数,如--initialize-at-build-time
.我的问题是如何解决这个问题?是否有要创建的配置文件,Micronaut 从选项中读取并转发到
native-image
可执行?
最佳答案
该问题是由 com.google.cloud:google-cloud-firestore:1.35.0
引起的以及它如何使用其依赖项。此依赖项不支持开箱即用的 native 图像。
正在努力在此官方存储库中添加对 GraalVM 的支持:
https://github.com/GoogleCloudPlatform/google-cloud-graalvm-support
将此库添加为编译依赖项可解决此问题。
关于 Micronaut 的 native 镜像配置,您可以通过配置文件传递选项。假设您的 groupId 是 com.acme
而你的 artifactId 是 acme-module1
,那么你需要在你的项目中创建文件 src/main/resources/META-INF/native-image/com/acme/acme-module1/native-image.properties
与您的内容:
Args = ...
关于java - 错误 : Classes that should be initialized at run time got initialized during image building: org. conscrypt.Conscrypt 被无意初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65461822/