Open joshlong opened 5 months ago
it breaks similarly with a Maven pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>22</java.version>
<spring-ai.version>0.8.1</spring-ai.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-vertex-ai-gemini-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>${spring-ai.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
When you add --verbose
to the native-image
build args, you can see the expanded list of arguments and their origin. Here's an excerpt for your reproducer:
...
'-H:ReflectionConfigurationResources@jar:file:///home/fniephaus/.gradle/caches/modules-2/files-2.1/io.netty/netty-codec/4.1.107.Final/a1d32debf2ed07c5852ab5b2904c43adb76c39e/netty-codec-4.1.107.Final.jar!/META-INF/native-image/io.netty/netty-codec/generated/handlers/reflect-config.json+api=META-INF/native-image/io.netty/netty-codec/generated/handlers/reflect-config.json' \
'-H:EnableURLProtocols@jar:file:///home/fniephaus/.gradle/caches/modules-2/files-2.1/com.google.api/gax/2.45.0/78ce52ef9330a8093c98579b70c93c5d9ee83e1b/gax-2.45.0.jar!/META-INF/native-image/com.google.api/gax/native-image.properties+api=https,http' \
'-H:ClassInitialization@jar:file:///home/fniephaus/.gradle/caches/modules-2/files-2.1/com.google.api/gax/2.45.0/78ce52ef9330a8093c98579b70c93c5d9ee83e1b/gax-2.45.0.jar!/META-INF/native-image/com.google.api/gax/native-image.properties+api=org.conscrypt:build_time,org.slf4j.LoggerFactory:build_time,org.junit.platform.engine.TestTag:build_time' \
'-H:ClassInitialization@jar:file:///home/fniephaus/.gradle/caches/modules-2/files-2.1/com.google.api/gax/2.45.0/78ce52ef9330a8093c98579b70c93c5d9ee83e1b/gax-2.45.0.jar!/META-INF/native-image/com.google.api/gax/native-image.properties+api=com.google.api.client.googleapis.services.AbstractGoogleClientRequest$ApiClientVersion:run_time' \
'-H:Features@jar:file:///home/fniephaus/.gradle/caches/modules-2/files-2.1/com.google.api/gax/2.45.0/78ce52ef9330a8093c98579b70c93c5d9ee83e1b/gax-2.45.0.jar!/META-INF/native-image/com.google.api/gax/native-image.properties+api=com.google.api.gax.nativeimage.OpenCensusFeature,com.google.api.gax.nativeimage.GoogleJsonClientFeature' \
...
I've searched for slf4j
through the list and found org.slf4j.LoggerFactory
. As we can see, it is registered for build-time initialization by com.google.api/gax
. The relevant and problematic native-image.properties
file is here. It seems the file was updated for GraalVM 22.2.0 two years ago and it's no longer working with --strict-image-heap
because the build-time initialize is incomplete: org.slf4j.LoggerFactory
allocates objects from the org.slf4j.helpers
package and those become part of the image heap. I don't think that gax
should even include build-time initialization for slf4j
.
In the meantime, this is how you can work around the build issue for now:
graalvmNative {
binaries.all {
buildArgs.add("--initialize-at-build-time=org.slf4j.helpers")
}
}
I have the same issue in one of my projects and I thought maybe someone might be interested in the Maven plugin configuration:
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<buildArgs>
<arg>--initialize-at-build-time=org.slf4j.helpers</arg>
</buildArgs>
</configuration>
</plugin>
it's not critical or anything but we should probably understand it..
code:
build:
error