Cannot resolve room dependencies in Kotlin only module

18 views Asked by At

I have an Android Studio project with a Kotlin only module in it that I'd like to use to implement database related code (in other words create the database, entities and DAO's) using Jetpack Room.

By reading the Declaring dependencies documentation, it is explicitly stated that:

Optionally, for non-Android libraries (i.e. Java or Kotlin only Gradle modules) you can depend on androidx.room:room-common to use Room annotations.

However, I can't compile the project because of errors listed below.

Here's my build.gradle file:

plugins {
    id("java-library")
    alias(libs.plugins.jetbrainsKotlinJvm)
    alias(libs.plugins.ksp)
}

java {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

ksp {
    arg("room.generateKotlin", "true")
}

dependencies {
    implementation(libs.room.ktx)
    implementation(libs.room.common)
    implementation(libs.room.runtime) <-- Needed so I can access `RoomDatabase` abstract class.
    ksp(libs.room.compiler)
}

Room dependencies in my libs.versions.toml file look like this:

[versions]
// ... other versions
kotlin = "1.9.0"
ksp = "1.9.0-1.0.12"
room = "2.6.1"
jetbrainsKotlinJvm = "1.9.0"

[libraries]
// ... other libs
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
room-common = { group = "androidx.room", name = "room-common", version.ref = "room" }
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
#room-testing = { group = "androidx.room", name = "room-testing", version.ref = "room" }

[plugins]
// ...other plugins
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
jetbrainsKotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "jetbrainsKotlinJvm" }

And this is the error I get when I try and sync the project:

Could not resolve: androidx.room:room-ktx:2.6.1
Could not resolve: androidx.room:room-runtime:2.6.1

My settings.gradle.kts is pretty basic, but it's referencing the google() repository.

I can't use the Room plugin to configure build options because it can only be ran in an Android module. Honestly, I'm lost. I've no clue why Gradle isn't able to reference those two libraries.

0

There are 0 answers