Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions generic-datastore-preferences/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,23 @@ kotlin {
commonMain.dependencies {
api(project(":generic-datastore-core"))
implementation(libs.coroutines.core)
api(libs.datastore.preferences.core)
api(libs.datastore.core)
compileOnly(libs.datastore.preferences.core)
api(libs.okio)
implementation(libs.kotlinx.io.core)
implementation(libs.kotlinx.serialization.json)
}

androidMain.dependencies {
api(libs.datastore.preferences)
}

jvmMain.dependencies {
api(libs.datastore.preferences.core)
}

iosMain.dependencies {
api(libs.datastore.preferences.core)
}
Comment on lines +22 to +38

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using compileOnly in commonMain for datastore.preferences.core is unnecessary and requires duplicating the dependency as api in jvmMain, iosMain, and potentially other targets.

Instead, you can keep api(libs.datastore.preferences.core) in commonMain. Gradle's dependency resolution will automatically handle the dependency on Android when androidMain declares api(libs.datastore.preferences) (since datastore-preferences transitively depends on datastore-preferences-core). This avoids duplicating the dependency for every other target platform and ensures that any future targets added to the project will automatically inherit the core dependency.

            api(libs.datastore.preferences.core)
            api(libs.okio)
            implementation(libs.kotlinx.io.core)
            implementation(libs.kotlinx.serialization.json)
        }

        androidMain.dependencies {
            api(libs.datastore.preferences)
        }

}
}

Expand Down
14 changes: 13 additions & 1 deletion generic-datastore-proto/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@ kotlin {
commonMain.dependencies {
api(project(":generic-datastore-core"))
implementation(libs.coroutines.core)
api(libs.datastore.core)
compileOnly(libs.datastore.core)
api(libs.datastore.core.okio)
api(libs.okio)
implementation(libs.kotlinx.io.core)
implementation(libs.kotlinx.serialization.json)
}

androidMain.dependencies {
api(libs.datastore.android.core)
}

jvmMain.dependencies {
api(libs.datastore.core)
}

iosMain.dependencies {
api(libs.datastore.core)
}
Comment on lines +22 to +39

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similarly, using compileOnly in commonMain for datastore.core is unnecessary and requires duplicating the dependency as api in jvmMain, iosMain, and other targets.

Keeping api(libs.datastore.core) in commonMain allows Gradle to resolve the dependency graph cleanly on Android when androidMain declares api(libs.datastore.android.core) (since androidx.datastore:datastore transitively depends on androidx.datastore:datastore-core). This eliminates the need to manually declare api(libs.datastore.core) in jvmMain and iosMain.

            api(libs.datastore.core)
            api(libs.datastore.core.okio)
            api(libs.okio)
            implementation(libs.kotlinx.io.core)
            implementation(libs.kotlinx.serialization.json)
        }

        androidMain.dependencies {
            api(libs.datastore.android.core)
        }

}
}

Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ leak-canary = { module = "com.squareup.leakcanary:leakcanary-android", version.r

datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastore" }
datastore-preferences-core = { module = "androidx.datastore:datastore-preferences-core", version.ref = "datastore" }

datastore-android-core = { module = "androidx.datastore:datastore", version.ref = "datastore" }
datastore-core = { module = "androidx.datastore:datastore-core", version.ref = "datastore" }

datastore-core-okio = { module = "androidx.datastore:datastore-core-okio", version.ref = "datastore" }
kotlinx-io-core = { module = "org.jetbrains.kotlinx:kotlinx-io-core", version.ref = "kotlinx-io" }
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
Expand Down
Loading