spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.24k stars 40.7k forks source link

SpringBoot 3.3.4 app, Hikari, MySQL and gradlew nativeCompile #42577

Closed jbiancot closed 1 month ago

jbiancot commented 1 month ago

Hello there,

I have a simple SpringBoot 3.3.4 app, I am trying a basic task, open a connection pool using Hikari, running a couple of SQL selects against a MySQL database. I am able to compile using:

./gradlew nativeCompile

Running it on a Apple Mac with M3 "arm64 chip"

java -version
java version "17.0.12" 2024-07-16 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 17.0.12+8.1 (build 17.0.12+8-LTS-jvmci-23.0-b41)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 17.0.12+8.1 (build 17.0.12+8-LTS-jvmci-23.0-b41, mixed mode, sharing)
gradle --version
------------------------------------------------------------
Gradle 8.10.1
------------------------------------------------------------

Build time:    2024-09-09 07:42:56 UTC
Revision:      8716158d3ec8c59e38f87a67f1f311f297b79576

Kotlin:        1.9.24
Groovy:        3.0.22
Ant:           Apache Ant(TM) version 1.10.14 compiled on August 16 2023
Launcher JVM:  17.0.12 (Oracle Corporation 17.0.12+8-LTS-jvmci-23.0-b41)
Daemon JVM:    /Library/Java/JavaVirtualMachines/graalvm-jdk-17.0.12+8.1/Contents/Home (no JDK specified, using current Java home)
OS:            Mac OS X 14.7 aarch64

but when I tried to run it, I am getting some issues. If I modify on gradle file with:

jar {
    archiveClassifier=''
    enabled = false
}

I can run it successfully using: java -jar build/libs/...

Some files it might be useful:

Gradle file: build.gradle.txt

Error on runtime / start-up errors.txt

wilkinsona commented 1 month ago

It looks like you're missing some reachability metadata for the MySQL JDBC Driver so it's unable to load some types reflectively. This could be because you're using the old Maven coordinates rather than the new ones. The new coordinates will match those used in the shared reachability metadata repository and allow its metadata to be used.

If the above doesn't help, it may be that you've configured JDBC in a way that means that it performs additional reflection and requires additional metadata or that the use of reflection has changed between 8.0.31 and 8.0.33. In this case, you could provide some additional metadata of your own to enable more use of reflection. You may also want to contribute this additional metadata back to the reachability metadata repository so that everyone benefits.

If you have any further questions, please follow up on Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.

jbiancot commented 1 month ago

@wilkinsona I tried a few things, it didn't work.

src/main/resources/META-INF/native-image]  tree
.
└── com.mysql
    ├── index.json
    └── mysql-connector-j
        └── 8.0.31
            ├── reflect-config.json
            └── resource-config.json

even I tried this:

native-image]  tree
.
├── com.mysql
│   ├── index.json
│   └── mysql-connector-j
│       └── 8.0.31
│           ├── reflect-config.json
│           └── resource-config.json
└── com.zaxxer
    └── HikariCP
        └── 5.0.1
            ├── jni-config.json
            ├── proxy-config.json
            ├── reflect-config.json
            ├── resource-config.json
            └── serialization-config.json

Then I don't understand how a feature so "game changer" as build native images "binaries", that only wants to implement basic interaction to one of the most popular databases as MySQL is, using one of the best connection pools like HikariCP, then I feel I need to do magic in order to make it work.

This needs work.

philwebb commented 1 month ago

@jbiancot Please remember that we're providing this software and trying to support it the best we can for free. Adding comments such as "This needs work." isn't a great way to get the help you're looking for!

Andy has already requested that you ask this question on https://stackoverflow.com rather that use this issue tracker, which we prefer to keep for bugs and enhancements. He also hinted that you may be using the incorrect group ID for the MySQL connector. Looking at the build.gradle file you attached, this looks likely to be the problem. If you do ask your question on https://stackoverflow.com, I would suggest providing a minimal reproducible example so that folks trying to help can reproduce the problem.

jbiancot commented 1 month ago

Hi @philwebb I have added the project to my website, if you have some time you can give it a try. I cleaned it a much as possible to make it very simple. You will need to have a MySQL/MariaDB database, setup connection string, e.g: setup IP, username and password. It will just try to get the version number from the database.

https://jesusbianco.com/stackoverflow/Test1-Native-Data-MySQL.zip

I also posted the question on Stack Overflow

https://stackoverflow.com/questions/79092147/springboot-3-3-4-app-hikari-mysql-and-gradlew-nativecompile