diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 6c4c4334..befe32c7 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -16,6 +16,7 @@ dependencies { // this allow us to access libs.anylibrary using type-safe accessors implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) + implementation(libs.koin.compiler.plugin) implementation(libs.android.gradle.plugin) implementation(libs.kotlin.gradle.plugin) implementation(libs.detekt.gradle.plugin) @@ -23,3 +24,12 @@ dependencies { implementation(libs.com.google.devtools.ksp.gradle.plugin) implementation(libs.popcorn.guineapig) } + +gradlePlugin { + plugins { + create("koinConvention") { + id = "com.streamplayer.koin-compiler-setup" + implementationClass = "KoinCompilerSetupPlugin" + } + } +} \ No newline at end of file diff --git a/build-logic/src/main/java/KoinCompilerSetupPlugin.kt b/build-logic/src/main/java/KoinCompilerSetupPlugin.kt new file mode 100644 index 00000000..3d08f2f0 --- /dev/null +++ b/build-logic/src/main/java/KoinCompilerSetupPlugin.kt @@ -0,0 +1,31 @@ +import gradle.kotlin.dsl.accessors._b237334f7e941d84ee6a2fb3c1888ffb.commonMainImplementation +import org.gradle.accessors.dm.LibrariesForLibs +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.dependencies +import org.gradle.kotlin.dsl.the +import org.koin.compiler.plugin.KoinGradleExtension + +// Ref: https://github.com/InsertKoinIO/koin-compiler-plugin/blob/main/docs/CASE_STUDY_NOW_IN_ANDROID.md#the-convention-plugin +class KoinCompilerSetupPlugin : Plugin { + override fun apply(target: Project) { + with(target) { + // Apply Koin Compiler Plugin (replaces KSP) + pluginManager.apply("io.insert-koin.compiler.plugin") + + // Configure logging + extensions.configure { + userLogs.set(true) + compileSafety.set(true) + } + + val libs = the() + + dependencies { + commonMainImplementation(libs.koin.core) + commonMainImplementation(libs.koin.annotations) + } + } + } +} \ No newline at end of file diff --git a/build-logic/src/main/java/com.streamplayer.koin-annotations-setup.gradle.kts b/build-logic/src/main/java/com.streamplayer.koin-annotations-setup.gradle.kts deleted file mode 100644 index 14d94977..00000000 --- a/build-logic/src/main/java/com.streamplayer.koin-annotations-setup.gradle.kts +++ /dev/null @@ -1,49 +0,0 @@ -import org.gradle.accessors.dm.LibrariesForLibs -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -val libs = the() - -plugins { - id("org.jetbrains.kotlin.multiplatform") - id("com.google.devtools.ksp") -} - -kotlin { - sourceSets { - commonMain.dependencies { - implementation(libs.koin.core) - api(libs.koin.annotations) - } - } - - // KSP Common sourceSet - sourceSets.named("commonMain").configure { - kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin") - } -} - -// KSP Tasks -dependencies { - add("kspCommonMainMetadata", libs.koin.ksp.compiler) -} - - -// WORKAROUND: ADD this dependsOn("kspCommonMainKotlinMetadata") instead of above dependencies -tasks.withType().configureEach { - if (name != "kspCommonMainKotlinMetadata") { - dependsOn("kspCommonMainKotlinMetadata") - } -} - -afterEvaluate { - tasks.filter { - it.name.contains("SourcesJar", true) - }.forEach { - println("SourceJarTask====>${it.name}") - it.dependsOn("kspCommonMainKotlinMetadata") - } -} - -ksp { - arg("KOIN_CONFIG_CHECK", "true") -} diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 5d3d0841..5474d0de 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -5,6 +5,7 @@ plugins { alias(libs.plugins.jetbrains.compose) alias(libs.plugins.compose.compiler) alias(libs.plugins.kotzilla) + id("com.streamplayer.koin-compiler-setup") } kotlin { diff --git a/composeApp/src/commonMain/kotlin/com.codandotv.streamplayerapp/di/AppModule.kt b/composeApp/src/commonMain/kotlin/com.codandotv.streamplayerapp/di/AppModule.kt index c10fa4a8..55e02e71 100644 --- a/composeApp/src/commonMain/kotlin/com.codandotv.streamplayerapp/di/AppModule.kt +++ b/composeApp/src/commonMain/kotlin/com.codandotv.streamplayerapp/di/AppModule.kt @@ -7,7 +7,6 @@ import com.codandotv.streamplayerapp.core_shared.qualifier.QualifierDispatcherIO import com.codandotv.streamplayerapp.feature_list_streams.list.di.ListStreamModule import com.codandotv.streamplayerapp.feature_news.di.NewsScreenModule import com.codandotv.streamplayerapp.feature_search.di.SearchModule -import com.codandotv.streamplayerapp.feature_search.presentation.widgets.StreamsError import com.codandotv.streamplayerapp.profile.di.ProfilePickerStreamModule import io.kotzilla.generated.monitoring import kotlinx.coroutines.Dispatchers @@ -16,7 +15,7 @@ import org.koin.core.KoinApplication import org.koin.core.context.startKoin import org.koin.core.lazyModules import org.koin.dsl.module -import org.koin.ksp.generated.module +import org.koin.plugin.module.dsl.modules fun streamPlayerApplication(platformBlock: KoinApplication.() -> Unit): KoinApplication { return startKoin { @@ -29,17 +28,17 @@ fun streamPlayerApplication(platformBlock: KoinApplication.() -> Unit): KoinAppl Dispatchers.IO } }, - NetworkModule().module, LocalStorageModule.module, SyncModule.module, // region feature_modules ListStreamModule.module, - SearchModule().module, - NewsScreenModule().module, - ProfilePickerStreamModule().module // endregion ) + modules() + modules() + modules() + modules() monitoring { onConfig { diff --git a/core-networking/build.gradle.kts b/core-networking/build.gradle.kts index 98fd7cd4..0b4c3f2a 100644 --- a/core-networking/build.gradle.kts +++ b/core-networking/build.gradle.kts @@ -5,7 +5,7 @@ plugins { alias(libs.plugins.jetbrains.compose) alias(libs.plugins.compose.compiler) alias(libs.plugins.buildkonfig.plugin) - id("com.streamplayer.koin-annotations-setup") + id("com.streamplayer.koin-compiler-setup") } buildkonfig { diff --git a/feature-news/build.gradle.kts b/feature-news/build.gradle.kts index 733114e7..484834f2 100644 --- a/feature-news/build.gradle.kts +++ b/feature-news/build.gradle.kts @@ -4,7 +4,7 @@ plugins { id("com.streamplayer.kmp-library") alias(libs.plugins.jetbrains.compose) alias(libs.plugins.compose.compiler) - id("com.streamplayer.koin-annotations-setup") + id("com.streamplayer.koin-compiler-setup") } kotlin { diff --git a/feature-profile/build.gradle.kts b/feature-profile/build.gradle.kts index 36b4c3b0..e816a4d1 100644 --- a/feature-profile/build.gradle.kts +++ b/feature-profile/build.gradle.kts @@ -4,7 +4,7 @@ plugins { id("com.streamplayer.kmp-library") alias(libs.plugins.jetbrains.compose) alias(libs.plugins.compose.compiler) - id("com.streamplayer.koin-annotations-setup") + id("com.streamplayer.koin-compiler-setup") } kotlin { diff --git a/feature-search/build.gradle.kts b/feature-search/build.gradle.kts index 05d5b8e0..af53108e 100644 --- a/feature-search/build.gradle.kts +++ b/feature-search/build.gradle.kts @@ -4,7 +4,7 @@ plugins { id("com.streamplayer.kmp-library") alias(libs.plugins.jetbrains.compose) alias(libs.plugins.compose.compiler) - id("com.streamplayer.koin-annotations-setup") + id("com.streamplayer.koin-compiler-setup") } kotlin { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 86b8306d..87e9a7b9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,6 +6,7 @@ koin-annotations = "2.3.1" ksp = "2.3.5" kotzilla = "2.1.3" lifecycle-viewmodel-compose-version = "2.9.6" +koin-compiler-plugin = "1.0.0-RC2" dokka = "1.9.10" detekt = "1.23.6" @@ -91,6 +92,7 @@ koin-ksp-compiler = { module = "io.insert-koin:koin-ksp-compiler", version.ref = koin_compose = { module = "io.insert-koin:koin-compose", version.ref = "koin" } koin_compose_viewmodel = { module = "io.insert-koin:koin-compose-viewmodel", version.ref = "koin" } koin_core_coroutines = { module = "io.insert-koin:koin-core-coroutines", version.ref = "koin" } +koin-compiler-plugin = { group = "io.insert-koin", name = "koin-compiler-gradle-plugin", version.ref = "koin-compiler-plugin" } #Networking okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }