chore(build, dependencies): add Room support with KSP integration and optimize testing dependencies

- Integrated Room plugin and runtime dependencies into `local-db` module, including schema configuration for Room.
- Added KSP processor dependencies for Kotlin Multiplatform compatibility.
- Enhanced `core-domain` module by refining and temporarily adjusting testing dependencies for resolution issues.
This commit is contained in:
2026-01-08 23:45:35 +01:00
parent ac5717c912
commit 6443edd386
10 changed files with 3516 additions and 164 deletions
+14
View File
@@ -5,6 +5,8 @@ import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.androidx.room)
alias(libs.plugins.ksp)
}
kotlin {
@@ -21,6 +23,8 @@ kotlin {
commonMain.dependencies {
implementation(libs.koin.core)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.androidx.room.runtime)
implementation(libs.androidx.sqlite.bundled)
}
jvmMain.dependencies {
@@ -34,3 +38,13 @@ kotlin {
}
}
}
room {
schemaDirectory("$projectDir/schemas")
}
dependencies {
add("kspCommonMainMetadata", libs.androidx.room.compiler)
add("kspJvm", libs.androidx.room.compiler)
// add("kspJs", libs.androidx.room.compiler) // Room compiler support for JS might vary, check specific version support
}
@@ -2,22 +2,33 @@
package at.mocode.frontend.core.localdb
import app.cash.sqldelight.db.SqlDriver
import androidx.room.RoomDatabase
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import org.koin.dsl.module
// Generated database class name from SQLDelight configuration
expect class DatabaseDriverFactory() {
suspend fun createDriver(): SqlDriver
// Abstract Room Database class definition
// @Database(entities = [MyEntity::class], version = 1) // Entities need to be defined
abstract class MeldestelleDb : RoomDatabase() {
// abstract fun myDao(): MyDao
}
// Convenience to create the typed database from a driver
expect class DatabaseProvider() {
suspend fun createDatabase(): MeldestelleDb
// Factory to create the database builder platform-specifically
expect class DatabaseBuilderFactory() {
fun create(): RoomDatabase.Builder<MeldestelleDb>
}
class DatabaseProvider(private val factory: DatabaseBuilderFactory) {
fun createDatabase(): MeldestelleDb {
return factory.create()
.setDriver(BundledSQLiteDriver())
.setQueryCoroutineContext(Dispatchers.IO)
.build()
}
}
// Koin module that exposes the database as a singleton
val localDbModule = module {
single { DatabaseDriverFactory() }
// Provide only the suspend-capable provider; consumers create the DB in a coroutine
single { DatabaseProvider() }
single { DatabaseBuilderFactory() }
single { DatabaseProvider(get()).createDatabase() }
}