spring-native
spring-native copied to clipboard
Remove remaining build time initialization (logging, hibernate validator, netty, etc.)
I tried to build image for my project using mvn spring-boot:build-image
and it failed. Log snippet as following.
Error: Classes that should be initialized at run time got initialized during image building: [INFO] [creator] org.apache.commons.logging.impl.SLF4JLocationAwareLog was unintentionally initialized at build time. To see why org.apache.commons.logging.impl.SLF4JLocationAwareLog got initialized use --trace-class-initialization=org.apache.commons.logging.impl.SLF4JLocationAwareLog [INFO] [creator] [INFO] [creator] Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception [INFO] [creator] Error: Image build request failed with exit status 1 [INFO] [creator] unable to invoke layer creator [INFO] [creator] unable to contribute native-image layer
My question is :
- How can I trace class initialization with Spring Boot Buildpacks support. I mean because this is not maven command option, I cannot use
mvn spring-boot:build-image --trace-class-initialization
. - How to solve this problem , specifically how can I avoid build time initialization , any hint will be appreciated.
I also encountered this problem when I added logback.xml to the Resource directory and the problem was restored when I deleted the logback.xml file
With Buildpacks --trace-class-initialization
should be added via BP_NATIVE_IMAGE_BUILD_ARGUMENTS
as described in this section.
We are working to remove default build time initialization, and indeed adding logback.xml
triggers this issue as well. I have turned this issue into a global "Remove remaining build time initialization" one.
I'm not sure but isn't it at least in case of the trigger duplicate of https://github.com/spring-projects-experimental/spring-native/issues/625
@phejl Sorry but not sure to fully understand your comment. What i can say is that solving this issue should help a lot for #625.
@sdeleuze Aha, I'm sorry. I missed your comment https://github.com/spring-projects-experimental/spring-native/issues/927#issuecomment-886467789 - that's what I tried to express.
I am getting a similar error (using latest plugin from main) although it is for object instantiation instead of class initialization, for jcl-over-slf4j
class SLF4JLocationAwareLog
. If I am using the gradle springAot
plugin, how do I specify --trace-object-instantiation
? The documentation says how to do it when using buildpacks and with the maven plugin but I don't see how to do it when using gradle.
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException:
No instances of org.apache.commons.logging.impl.SLF4JLocationAwareLog are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use
--trace-object-instantiation=org.apache.commons.logging.impl.SLF4JLocationAwareLog.
at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.checkImageHeapInstance(ClassInitializationFeature.java:134)
You can use NativeHint(options = "--trace-object-instantiation=org.apache.commons.logging.impl.SLF4JLocationAwareLog")
. Feel free to comment if you think we should update default initialization hint based on your findings.
We are progressing on that one, with a collaboration with GraalVM team on Netty, but that will take more time than expected so I bring back this one to the backlog.
Any resolve on the above i seem to be getting the same error
[creator] [2/7] Performing analysis... [] (17.4s @ 1.60GB) [creator] To see how the classes got initialized, use --trace-class-initialization=org.springframework.util.unit.DataSize [creator] 6,948 (89.29%) of 7,781 classes reachable [creator] 10,074 (71.60%) of 14,070 fields reachable [creator] 33,053 (81.94%) of 40,339 methods reachable [creator] 153 classes, 70 fields, and 1,256 methods registered for reflection [creator] er:bootBuildImage [creator] Error: Classes that should be initialized at run time got initialized during image building: [creator] org.springframework.util.unit.DataSize was unintentionally initialized at build time. To see why org.springframework.util.unit.DataSize got initialized use --trace-class-initialization=org.springframework.util.unit.DataSize
@nyakaz73 Something is likely wrong with your setup since this is fixed out of the box by Spring Native for a long time. In the meantime, you can follow https://github.com/oracle/graal/issues/4489 to see the proper resolution at GraalVM level.
Spring Native is now superseded by Spring Boot 3 official native support, see the related reference documentation for more details.
As a consequence, I am closing this issue, and recommend trying your use case with latest Spring Boot 3 version. If you still experience the issue reported here, please open an issue directly on the related Spring project (Spring Framework, Data, Security, Boot, Cloud, etc.) with a reproducer.
Thanks for your contribution on the experimental Spring Native project, we hope you will enjoy the official native support introduced by Spring Boot 3.