https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
j

Jason Zhao

11/27/2023, 11:39 PM
Hi, I have an issue that I am stuck on when trying to convert my SQLDelight R2DBC setup to use connection pools. Not directly an issue with SQLDelight, but rather R2DBC but it is really strange so I am asking for help here. When using R2DBC it seems like the driver detection only finds either the "pool" or "postgresql" driver but not both. I already specify an "api()" dependency on both the postgresql and pool modules in the gradle file. Whether the "pool" or "postgresql" driver is loaded in a particular build is apparently random and I suspect it's based on the order in which I define it in
build.gradle.kts
. But always exactly one of the two drivers gets detected. Here is the erroring code (just trying to make a R2DBC connection pool):
Copy code
pooledConnectionFactory = ConnectionFactories.get(
    ConnectionFactoryOptions.builder()
        .option(ConnectionFactoryOptions.DRIVER, "pool")
        .option(ConnectionFactoryOptions.PROTOCOL, "postgresql")
        .option(ConnectionFactoryOptions.HOST, config.host)
        .option(ConnectionFactoryOptions.PORT, config.port)
        .option(ConnectionFactoryOptions.USER, config.username)
        .option(ConnectionFactoryOptions.PASSWORD, config.password)
        .option(ConnectionFactoryOptions.DATABASE, config.database)
        .build()
)
This is the error (in this case it found "pool" but didn't find "postgresql"):
Exception in thread "DefaultDispatcher-worker-2" java.lang.IllegalArgumentException: Could not find delegating driver [postgresql]
I have a really unusual setup though. The project is a multi-module KMP project, and the module I am building compiles to a Minecraft plugin (Spigot API) which loads after the game server itself, so that might be a potential issue. The module that has the R2DBC dependencies is different from the Minecraft module which is being compiled. Both of the dependencies do show in the compiled JAR file as shown in the image below. Anyone know what is wrong with my setup and how to get both drivers to be detected?
h

hfhbd

11/28/2023, 6:17 AM
If you want to auto load the driver you have to take a look of your actual classpath at runtime. Gradle itself ensures a deterministic classpath using the order of our dependencies, but you mentioned your are running at the minecraft server so you need to fix this classpath. Alternatively you should also be able to configure the driver with “real code” without service loader mechanism, I think
j

Jason Zhao

11/28/2023, 1:23 PM
I will look into the method without service loader, thanks
2 Views