Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for koin-annotations in peristence module. #68

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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
34 changes: 0 additions & 34 deletions convention-plugins/src/main/kotlin/koin-annotations.gradle.kts

This file was deleted.

6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
agp = "8.2.2"
kotlin = "1.9.23"
ksp = "1.9.23-1.0.20" # Must be compatible with: `kotlin`
kotlin = "1.9.24"
ksp = "1.9.24-1.0.20" # Must be compatible with: `kotlin`
desugarLibs = "1.1.5"
androidxComposeBom = "2024.01.00"
androidxActivity = "1.7.2"
Expand Down Expand Up @@ -129,10 +129,10 @@ ktorfit = { id = "de.jensklingenberg.ktorfit", version.ref = "ktorfit" }
skie = { id = "co.touchlab.skie", version.ref = "skie" }
buildkonfig = { id = "com.codingfeline.buildkonfig", version.ref = "buildkonfig" }
moko-resources = { id = "dev.icerock.mobile.multiplatform-resources", version.ref = "moko-resources" }
ksp = { id ="com.google.devtools.ksp", version.ref = "ksp" }

# Precompiled script plugins
conventions-lint = { id = "conventions-lint" }
koin-annotations-plugin = { id = "koin-annotations" }

[bundles]
compose = [
Expand Down
20 changes: 19 additions & 1 deletion shared/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ plugins {
id(libs.plugins.com.android.library.get().pluginId)
id(libs.plugins.kotlin.multiplatform.get().pluginId)
id(libs.plugins.conventions.lint.get().pluginId)
id(libs.plugins.koin.annotations.plugin.get().pluginId)

alias(libs.plugins.ksp)
alias(libs.plugins.skie)
alias(libs.plugins.moko.resources)
}
Expand Down Expand Up @@ -133,3 +133,21 @@ multiplatformResources {
multiplatformResourcesClassName = "MR"
iosBaseLocalizationRegion = ProjectSettings.IOS.MokoBaseLocalizationRegion
}

ksp {
// enable compile time check
arg("KOIN_CONFIG_CHECK","false")
// disable default module generation
arg("KOIN_DEFAULT_MODULE","false")
}

dependencies {
add("kspCommonMainMetadata", libs.koin.ksp.compiler)
}

// WORKAROUND: This somehow makes ksp generate stuff. I have no idea why.
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach {
if (name != "kspCommonMainKotlinMetadata") {
dependsOn("kspCommonMainKotlinMetadata")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app.futured.kmptemplate.app.injection
import app.futured.kmptemplate.feature.injection.FeatureModule
import app.futured.kmptemplate.network.graphql.injection.NetworkGraphqlModule
import app.futured.kmptemplate.network.rest.injection.NetworkRestModule
import app.futured.kmptemplate.persistence.injection.persistenceModule
import app.futured.kmptemplate.persistence.injection.PersistenceModule
import app.futured.kmptemplate.platform.binding.PlatformBindings
import app.futured.kmptemplate.platform.injection.platformModule
import org.koin.core.context.startKoin
Expand All @@ -30,7 +30,7 @@ internal object AppInjection {
FeatureModule().module,
NetworkGraphqlModule().module,
NetworkRestModule().module,
persistenceModule(),
PersistenceModule().module,
)
}
}
Expand Down
20 changes: 19 additions & 1 deletion shared/feature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ plugins {
id(libs.plugins.kotlin.multiplatform.get().pluginId)
id(libs.plugins.kotlin.parcelize.get().pluginId)
id(libs.plugins.conventions.lint.get().pluginId)
id(libs.plugins.koin.annotations.plugin.get().pluginId)

alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.ksp)
}

dependencies {
Expand Down Expand Up @@ -82,3 +82,21 @@ android {
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}
}

ksp {
// enable compile time check
arg("KOIN_CONFIG_CHECK","false")
// disable default module generation
arg("KOIN_DEFAULT_MODULE","false")
}

dependencies {
add("kspCommonMainMetadata", libs.koin.ksp.compiler)
}

// WORKAROUND: This somehow makes ksp generate stuff. I have no idea why.
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach {
if (name != "kspCommonMainKotlinMetadata") {
dependsOn("kspCommonMainKotlinMetadata")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app.futured.kmptemplate.feature.domain

import app.futured.kmptemplate.persistence.persistence.ApplicationSettingsPersistence
import app.futured.kmptemplate.util.domain.UseCase
import org.koin.core.annotation.Factory

@Factory
internal class SaveDummyPersistenceValueUseCase(
private val applicationSettingsPersistence: ApplicationSettingsPersistence
) : UseCase<Boolean, Unit>() {

override suspend fun build(args: Boolean) {
applicationSettingsPersistence.setDummyValue(args)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.futured.kmptemplate.feature.ui.login

import app.futured.kmptemplate.feature.domain.SaveDummyPersistenceValueUseCase
import app.futured.kmptemplate.feature.navigation.root.RootSlotNavigator
import app.futured.kmptemplate.network.graphql.api.RickAndMortyApi
import app.futured.kmptemplate.network.rest.api.StarWarsApi
Expand All @@ -15,6 +16,7 @@ internal class LoginViewModel(
private val starWarsApi: StarWarsApi,
private val rickAndMortyApi: RickAndMortyApi,
private val navigator: RootSlotNavigator,
private val saveDummyPersistenceValueUseCase: SaveDummyPersistenceValueUseCase,
) : SharedViewModel<LoginViewState, Nothing>(),
LoginScreen.Actions,
LoginScreen.SuspendActions {
Expand All @@ -25,6 +27,11 @@ internal class LoginViewModel(
init {
testRestApiClient()
testGraphqlApiClient()

// Just to verify [ApplicationSettingsPersistence] gets properly injected
launchWithHandler {
saveDummyPersistenceValueUseCase.execute(false).getOrThrow()
}
}

private fun testRestApiClient() = launchWithHandler {
Expand Down
20 changes: 19 additions & 1 deletion shared/network/graphql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ plugins {
id(libs.plugins.com.android.library.get().pluginId)
id(libs.plugins.kotlin.multiplatform.get().pluginId)
id(libs.plugins.conventions.lint.get().pluginId)
id(libs.plugins.koin.annotations.plugin.get().pluginId)

alias(libs.plugins.ksp)
alias(libs.plugins.apollo)
alias(libs.plugins.buildkonfig)
}
Expand Down Expand Up @@ -91,3 +91,21 @@ buildkonfig {
}
}
}

ksp {
// enable compile time check
arg("KOIN_CONFIG_CHECK", "false")
// disable default module generation
arg("KOIN_DEFAULT_MODULE", "false")
}

dependencies {
add("kspCommonMainMetadata", libs.koin.ksp.compiler)
}

// WORKAROUND: This somehow makes ksp generate stuff. I have no idea why.
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach {
if (name != "kspCommonMainKotlinMetadata") {
dependsOn("kspCommonMainKotlinMetadata")
}
}
20 changes: 19 additions & 1 deletion shared/network/rest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ plugins {
id(libs.plugins.com.android.library.get().pluginId)
id(libs.plugins.kotlin.multiplatform.get().pluginId)
id(libs.plugins.conventions.lint.get().pluginId)
id(libs.plugins.koin.annotations.plugin.get().pluginId)

alias(libs.plugins.ksp)
alias(libs.plugins.ktorfit)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.buildkonfig)
Expand Down Expand Up @@ -88,3 +88,21 @@ buildkonfig {
}
}
}

ksp {
// enable compile time check
arg("KOIN_CONFIG_CHECK","false")
// disable default module generation
arg("KOIN_DEFAULT_MODULE","false")
}

dependencies {
add("kspCommonMainMetadata", libs.koin.ksp.compiler)
}

// WORKAROUND: This somehow makes ksp generate stuff. I have no idea why.
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach {
if (name != "kspCommonMainKotlinMetadata") {
dependsOn("kspCommonMainKotlinMetadata")
}
}
50 changes: 40 additions & 10 deletions shared/persistence/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ plugins {
id(libs.plugins.conventions.lint.get().pluginId)

alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.ksp)
}

android {
namespace = libs.versions.project.shared.persistence.namespace.get()
compileSdk = ProjectSettings.Android.CompileSdkVersion
defaultConfig {
minSdk = ProjectSettings.Android.MinSdkVersion
}
compileOptions {
sourceCompatibility = ProjectSettings.Android.JavaCompatibility
targetCompatibility = ProjectSettings.Android.JavaCompatibility
}
}

kotlin {
Expand All @@ -23,16 +36,25 @@ kotlin {
iosTargets()

sourceSets {
androidMain {
kotlin.srcDir("build/generated/ksp/android/androidDebug/kotlin")
kotlin.srcDir("build/generated/ksp/android/androidRelease/kotlin")
}
iosMain {
kotlin.srcDir("build/generated/ksp/iosArm64/iosArm64Main/kotlin")
kotlin.srcDir("build/generated/ksp/iosSimulatorArm64/iosSimulatorArm64Main/kotlin")
kotlin.srcDir("build/generated/ksp/iosX64/iosX64Main/kotlin")
}
commonMain {
dependencies {
implementation(libs.koin.core)
implementation(libs.koin.annotations)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.logging.kermit)
implementation(libs.kotlinx.serialization.json)
implementation(libs.androidx.datastore.preferences.core)
}
}

commonTest {
dependencies {
implementation(libs.kotlin.testCommon)
Expand All @@ -42,14 +64,22 @@ kotlin {
}
}

android {
namespace = libs.versions.project.shared.persistence.namespace.get()
compileSdk = ProjectSettings.Android.CompileSdkVersion
defaultConfig {
minSdk = ProjectSettings.Android.MinSdkVersion
}
compileOptions {
sourceCompatibility = ProjectSettings.Android.JavaCompatibility
targetCompatibility = ProjectSettings.Android.JavaCompatibility
ksp {
// enable compile time check
arg("KOIN_CONFIG_CHECK", "false")
// disable default module generation
arg("KOIN_DEFAULT_MODULE", "false")
}

dependencies {
add("kspAndroid", libs.koin.ksp.compiler)
add("kspIosX64", libs.koin.ksp.compiler)
add("kspIosArm64", libs.koin.ksp.compiler)
add("kspIosSimulatorArm64", libs.koin.ksp.compiler)
}

tasks.matching { it.name == "compileIosMainKotlinMetadata" }.configureEach {
if (project.tasks.findByName("kspKotlinIosSimulatorArm64") != null) {
dependsOn("kspKotlinIosSimulatorArm64")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app.futured.kmptemplate.persistence.injection

import android.content.Context
import app.futured.kmptemplate.persistence.tools.SETTINGS_DATASTORE_FILENAME
import okio.Path
import okio.Path.Companion.toPath
import org.koin.core.annotation.Named
import org.koin.core.annotation.Single

@Single
@Named("DataStoreFilePath")
internal fun dataStoreFilePath(context: Context): Path =
context.filesDir.resolve(SETTINGS_DATASTORE_FILENAME).absolutePath.toPath()

This file was deleted.

Loading
Loading