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

アウスジョン(アウス)

10/26/2023, 11:53 AM
Hello, In a multiplatform project, is it not possible to have the database folder associated with
jvmMain
? Even when I setting
srcDirs
to
src/jvmMain/sqldelight
, the database seems to associated to
commonMain
and the gradle build crashes because it isn't able to detect jdbc-driver.
Here is my gradle file and the folder structure
Copy code
import com.varabyte.kobweb.gradle.application.util.configAsKobwebApplication

buildscript {
    dependencies {
        classpath("app.cash.sqldelight:gradle-plugin:2.0.0")
    }
}

plugins {
    alias(libs.plugins.kotlin.multiplatform)
    alias(libs.plugins.jetbrains.compose)
    alias(libs.plugins.kobweb.application)
    id("app.cash.sqldelight") version "2.0.0"
    // alias(libs.plugins.kobwebx.markdown)
}

group = "org.example.ksql4"
version = "1.0-SNAPSHOT"

kobweb {
    app {
        index {
            description.set("Powered by Kobweb")
        }
    }
}

kotlin {
    configAsKobwebApplication("ksql4", includeServer = true)

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(compose.runtime)
            }
        }

        val jsMain by getting {
            dependencies {
                implementation(compose.html.core)
                implementation(libs.kobweb.core)
                implementation(libs.kobweb.silk)
                implementation(libs.silk.icons.fa)
                // implementation(libs.kobwebx.markdown)
            }
        }
        val jvmMain by getting {
            dependencies {
                implementation(libs.kobweb.api)
                implementation("app.cash.sqldelight:sqlite-driver:2.0.0")
                implementation("app.cash.sqldelight:jdbc-driver:2.0.0")
                implementation("app.cash.sqldelight:runtime:2.0.0")
                implementation("com.zaxxer:HikariCP:5.0.1")
                implementation("org.slf4j:slf4j-simple:2.0.7")
            }
        }
    }
}

sqldelight {
    databases {
        create("Database") {
            packageName.set("org.example.ksql4.database")
            dialect("app.cash.sqldelight:mysql-dialect:2.0.0")
            deriveSchemaFromMigrations.set(true)
            srcDirs.setFrom("src/jvmMain/sqldelight")
        }
    }
}
j

jw

10/26/2023, 11:56 AM
Not currently
You can put the database in a JVM module and depend on that from jvmMain
u

アウスジョン(アウス)

10/26/2023, 12:02 PM
Does it mean it's not currently possible to use the jdbc driver directly in a multiplatform project?
j

jw

10/26/2023, 12:08 PM
The JDBC driver only works on the JVM so you'd only be able to use it from jvmMain in a multiplatform module.
🆗 1