At the moment I’m using Logback in my Compose Desk...
# compose-desktop
k
At the moment I’m using Logback in my Compose Desktop app and I’m seeing some weird behaviour. Run the KMP wizard and create a project, mine is Desktop only. In that project I add two libraries, SQLite and Logback
Copy code
[versions]
sqLiteVersion = "3.45.3.0"
logback_version = "1.5.6"


[libraries]
sqlite = { module = "org.xerial:sqlite-jdbc", version.ref = "sqLiteVersion" }
logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback_version" }
I also reference these in my build.gradle file
Copy code
desktopMain.dependencies {
            implementation(libs.logback)
            implementation(libs.sqlite)
        }
In
main
I add code to access a database
Copy code
val connectionString = "jdbc:sqlite:${databaseDirectory}foo.sqlite"

    val connection = DriverManager.getConnection(connectionString)

    val stmt = connection.createStatement()
    val rs = stmt.executeQuery("select * from competitions")
    while (rs.next()) {
        println(rs.getString("id"))
    }
If I run the app, this all works. If I use
compose desktop:runDistributable
then it also works. What I then do is add a logback.xml file to desktopMain/resources and then try and run
compose desktop:runDistributable
then I get an exception
Copy code
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:sqlite:/Users/kevinjones/.ksstats/cricket.sqlite
	at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
	at ComposableSingletons$MainKt$lambda-2$1.invoke(main.kt:16)
	at ComposableSingletons$MainKt$lambda-2$1.invoke(main.kt:6)
    ...
If I take that logback.xml file and remove all its contents then everything works again. If the logback.xml file simply contains
Copy code
<configuration>
</configuration>
then it fails, so there’s nothing in this file that causes an error. I’ve tried various combinations of putting the references to logback and sqlite in different source sets, and putting logback.xml in different source sets but the error persists. This is on an Apple Silicon Mac.
Switching to log4j threw a different exception, one that showed I needed to include the ‘java.management’ module. Switching back to logback I still get the same exception, however changing to
includeAllModules = true
in the gradle file also fixed the code using logback, unfortunately there’s no hint as to what modules I also need to include (
suggestRuntimeModules
doesn’t help) Is there any other way of getting the modules I need for the application?
a
You need
java.sql
module, and you might also need to update Proguard rules
If you want to know which modules your app need from Java runtime, use
jdeps
or try to build the release application with the warnings, you will know from the java imports, including all modules will make the distributable app bundle bigger
110 Views