oracle / graalvm-reachability-metadata

Repository which contains community-driven collection of GraalVM reachability metadata for open-source libraries.
Creative Commons Zero v1.0 Universal
395 stars 102 forks source link

Support of hibernate-validator 8.0.2.Final acording to Frameworks Ready for Native Image #629

Open courteous opened 1 month ago

courteous commented 1 month ago

Describe the problem

Hello I have the following question:

I have a spring boot app which can be successfully compiled and an java -jar is able to run the app without any problems.

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.4.5</version>
    </parent>

and

java --version 
java 24.0.1 2025-04-15 
Java(TM) SE Runtime Environment Oracle GraalVM 24.0.1+9.1 (build 24.0.1+9-jvmci-b01) 
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 24.0.1+9.1 (build 24.0.1+9-jvmci-b01, mixed mode, sharing)

I decided to move my app to the Native Image and for that I first made sure that all my java modules can be compiled as native image. All those modules were successfully compiled to native image using the native-maven-plugin. Then I decides to move the main server app to the native image again using the standard native-maven-plugin. Now the problem i discovered the compilation of the main app is one particular dependencies can not be resolved based on the reachability metadata repository in my particular case that is the hibernate-validator:8.0.2.Final.

attaching the partial compilation output below:

[INFO] Found GraalVM installation from JAVA_HOME variable. 
[INFO] Downloaded GraalVM reachability metadata repository from file:/home/tito/.m2/repository/org/graalvm/buildtools/graalvm-reachability-metadata/0.10.6/graalvm-reachability-metadata-0.10.6-repository.zip 
[INFO] [graalvm reachability metadata repository for ch.qos.logback:logback-classic:1.5.18]: Configuration directory not found. Trying latest version. 
[INFO] [graalvm reachability metadata repository for ch.qos.logback:logback-classic:1.5.18]: Configuration directory is ch.qos.logback/logback-classic/1.4.9 
[INFO] [graalvm reachability metadata repository for com.fasterxml.jackson.core:jackson-databind:2.18.3]: Configuration directory not found. Trying latest version. 
[INFO] [graalvm reachability metadata repository for com.fasterxml.jackson.core:jackson-databind:2.18.3]: Configuration directory is com.fasterxml.jackson.core/jackson-databind/2.15.2 
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:8.0.2.Final]: Configuration directory not found. Trying latest version. 
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:8.0.2.Final]: Configuration directory is org.hibernate.validator/hibernate-validator/7.0.4.Final 
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:8.0.2.Final]: Configuration directory not found. Trying latest version. 
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:8.0.2.Final]: Latest version not found! 
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:8.0.2.Final]: missing. 
[INFO] [graalvm reachability metadata repository for org.thymeleaf:thymeleaf-spring6:3.1.3.RELEASE]: Configuration directory not found. Trying latest version. 
[INFO] [graalvm reachability metadata repository for org.thymeleaf:thymeleaf-spring6:3.1.3.RELEASE]: Configuration directory is org.thymeleaf/thymeleaf-spring6/3.1.0.M2 
[INFO] [graalvm reachability metadata repository for org.thymeleaf:thymeleaf:3.1.3.RELEASE]: Configuration directory not found. Trying latest version. 
[INFO] [graalvm reachability metadata repository for org.thymeleaf:thymeleaf:3.1.3.RELEASE]: Configuration directory is org.thymeleaf/thymeleaf/3.1.0.RC1 
[INFO] [graalvm reachability metadata repository for org.apache.tomcat.embed:tomcat-embed-core:10.1.40]: Configuration directory not found. Trying latest version. 
[INFO] [graalvm reachability metadata repository for org.apache.tomcat.embed:tomcat-embed-core:10.1.40]: Configuration directory is org.apache.tomcat.embed/tomcat-embed-core/10.0.20 
[INFO] [graalvm reachability metadata repository for org.freemarker:freemarker:2.3.34]: Configuration directory not found. Trying latest version. 
[INFO] [graalvm reachability metadata repository for org.freemarker:freemarker:2.3.34]: Configuration directory is org.freemarker/freemarker/2.3.31 
[INFO] [graalvm reachability metadata repository for org.hibernate.orm:hibernate-core:6.6.13.Final]: Configuration directory not found. Trying latest version. 
[INFO] [graalvm reachability metadata repository for org.hibernate.orm:hibernate-core:6.6.13.Final]: Configuration directory is org.hibernate.orm/hibernate-core/6.6.0.Final 
[INFO] [graalvm reachability metadata repository for org.glassfish.jaxb:jaxb-runtime:4.0.5]: Configuration directory not found. Trying latest version. 
[INFO] [graalvm reachability metadata repository for org.glassfish.jaxb:jaxb-runtime:4.0.5]: Configuration directory is org.glassfish.jaxb/jaxb-runtime/3.0.2 
[INFO] [graalvm reachability metadata repository for org.jboss.logging:jboss-logging:3.6.1.Final]: Configuration directory not found. Trying latest version. 
[INFO] [graalvm reachability metadata repository for org.jboss.logging:jboss-logging:3.6.1.Final]: Configuration directory is org.jboss.logging/jboss-logging/3.5.0.Final 
[INFO] [graalvm reachability metadata repository for org.postgresql:postgresql:42.7.5]: Configuration directory not found. Trying latest version. 
[INFO] [graalvm reachability metadata repository for org.postgresql:postgresql:42.7.5]: Configuration directory is org.postgresql/postgresql/42.7.3

now in order to troubleshoot that further I decided to use the, maven-shade-plugin , and I was really surprised that once I replaced the spring-boot-maven-plugin with the maven-shade-plugin. In this case the app was compiled by the native image was !!! successful !!!! , although the same warring existed about the hibernate-validator version 8.0.2.Final. as present as well once I compiled with pring-boot-maven-plugin. Once the compilation was finished the final result was that the program was not able to run and I got the AotInitializerNotFoundException. i.e. see the stack trace below:


:: Spring Boot ::                (v3.4.5) 

Application run failed 
org.springframework.boot.AotInitializerNotFoundException: Startup with AOT mode enabled failed: AOT initializer org.server.core.Application__ApplicationContextInitializer could not be found 
       at org.springframework.boot.SpringApplication.addAotGeneratedInitializerIfNecessary(SpringApplication.java:426) 
       at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:382) 
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:317) 
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:1362) 
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:1351) 
       at org.server.core.Application.main(Application.java:109) 
       at java.base@24.0.1/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

Everything so far is very similar to what is descried here.

Now at this point, I thought that this library (hibernate-validator 8.0.2.Final ) was not supported, but that is not the case. I found it listed as officially supported here

i.e. anything above or equal to version 7.0.4 is supported!

But for some reason that is not working for me.

I would really appreciate some guidance on how to troubleshoot this further.

In this particular case the jar hibernate-validator 8.0.2.Final is being pulled automatically because of the following dependency "spring-boot-starter-validation" which is part of the POM. i.e.

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>

Image

I am attaching some relative parts of the POM.

    ```
<!--             
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>

            <configuration>
                <mainClass>org.server.core.Application</mainClass>
                <layout>JAR</layout>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>

        </plugin>
        -->

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.6.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>

                <configuration>

                </configuration>

                </execution>
            </executions>
        </plugin>

                <plugin>
            <groupId>org.graalvm.buildtools</groupId>
            <artifactId>native-maven-plugin</artifactId>

            <extensions>true</extensions>
            <executions>
                <execution>
                    <id>build-native</id>
                    <goals>
                        <goal>compile-no-fork</goal>
                    </goals>
                    <phase>package</phase>
                </execution>
            </executions>

            <configuration>
                <mainClass>org.server.core.Application</mainClass>
            </configuration>

        </plugin>
courteous commented 1 month ago

I have tired today manually overriding the hibernate-validator version in the POM to the latest one which is mentioned that is supported and still the maven repo did not find any supported version.

i.e.

        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>7.0.4.Final</version>
        </dependency>

result was

[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:7.0.4.Final]: Configuration directory is org.hibernate.validator/hibernate-validator/7.0.4.Final
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:7.0.4.Final]: Configuration directory not found. Trying latest version.
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:7.0.4.Final]: Latest version not found!
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:7.0.4.Final]: missing.