Skip to content

Commit

Permalink
Feat: KMP Library Setup (#1766)
Browse files Browse the repository at this point in the history
* Migrating from hilt to koin (This) (#1764)

* Migrating from hilt to koin

* Fixed Instance creation error

* refactor: Removed Hilt and migrated to Koin

This commit removes Hilt and migrates the project to Koin for dependency injection.

The following
 changes were made:

- Removed the `AndroidHiltConventionPlugin`.
- Added the `AndroidKoinConventionPlugin`.
- Updated dependencies to use Koin.
- Updated KSP configuration for Koin.
- Updated feature modules to use Koin.
- Updated common modules to use Koin
.
- Removed Hilt annotations and replaced them with Koin annotations.
- Updated ViewModels to use Koin for dependency injection.
- Updated modules to use Koin for dependency injection.

* Formatted Dependencies

* migrating from hilt to koin clean up commit

* Revert "migrating from hilt to koin clean up commit"

This reverts commit bb63058.

---------

Co-authored-by: Sk Niyaj Ali <[email protected]>

* Feat: KMP Library Setup

---------

Co-authored-by: Nagarjuna <[email protected]>
  • Loading branch information
niyajali and Nagarjuna0033 authored Sep 24, 2024
1 parent 3ce0b36 commit 348ec06
Show file tree
Hide file tree
Showing 316 changed files with 4,280 additions and 3,170 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/master_dev_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ jobs:
run: ./gradlew :mifospay:assembleDemoDebug

- name: Check badging
# This step is allowed to fail, as it's not critical for the build
continue-on-error: true
run: ./gradlew :mifospay:checkProdReleaseBadging

- name: Upload APKs
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/monthly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ name: Bump our Calendar Version

on:
workflow_dispatch:
schedule:
- cron: '30 3 1 * *'
# This is a monthly cron job that runs on the first of the month at 3:30 AM UTC
# Turning off for now
# schedule:
# - cron: '30 3 1 * *'
jobs:
tag:
name: Tag Monthly Release
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/weekly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ name: Tag Weekly Release

on:
workflow_dispatch:
schedule:
- cron: '0 4 * * 0'
# This is a weekly cron job that runs every Sunday at 4:00 AM UTC
# Turning off for now
# schedule:
# - cron: '0 4 * * 0'
jobs:
tag:
name: Tag Weekly Release
Expand Down
24 changes: 20 additions & 4 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ gradlePlugin {
id = "mifospay.android.application"
implementationClass = "AndroidApplicationConventionPlugin"
}
register("androidHilt") {
id = "mifospay.android.hilt"
implementationClass = "AndroidHiltConventionPlugin"
}
register("androidLibraryCompose") {
id = "mifospay.android.library.compose"
implementationClass = "AndroidLibraryComposeConventionPlugin"
Expand All @@ -64,6 +60,10 @@ gradlePlugin {
implementationClass = "AndroidLibraryConventionPlugin"
}
register("androidFeature") {
id = "mifospay.cmp.feature"
implementationClass = "CMPFeatureConventionPlugin"
}
register("cmpFeature") {
id = "mifospay.android.feature"
implementationClass = "AndroidFeatureConventionPlugin"
}
Expand All @@ -87,10 +87,26 @@ gradlePlugin {
id = "mifospay.jvm.library"
implementationClass = "JvmLibraryConventionPlugin"
}
register("kmpLibrary") {
id = "mifospay.kmp.library"
implementationClass = "KMPLibraryConventionPlugin"
}
register("kotlinInject") {
id = "mifospay.kmp.inject"
implementationClass = "KotlinInjectConventionPlugin"
}
register("androidFlavors") {
id = "mifospay.android.application.flavors"
implementationClass = "AndroidApplicationFlavorsConventionPlugin"
}
register("androidKoin") {
id = "mifospay.android.koin"
implementationClass = "KoinConventionPlugin"
}
register("kmpKoin") {
id = "mifospay.kmp.koin"
implementationClass = "KMPKoinConventionPlugin"
}
register("detekt") {
id = "mifos.detekt.plugin"
implementationClass = "MifosDetektConventionPlugin"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.internal.scope.ProjectInfo.Companion.getBaseName
import com.google.devtools.ksp.gradle.KspExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
Expand All @@ -12,8 +13,9 @@ class AndroidFeatureConventionPlugin : Plugin<Project> {
with(target) {
pluginManager.apply {
apply("mifospay.android.library")
apply("mifospay.android.hilt")
apply("mifospay.android.koin")
}

extensions.configure<LibraryExtension> {
defaultConfig {
// set custom test runner
Expand All @@ -22,28 +24,42 @@ class AndroidFeatureConventionPlugin : Plugin<Project> {
testOptions.animationsDisabled = true
}

extensions.configure<KspExtension> {
arg("KOIN_USE_COMPOSE_VIEWMODEL","true")
}

dependencies {
add("implementation", project(":core:ui"))
add("implementation", project(":core:designsystem"))
add("implementation", project(":core:data"))

add("implementation", project(":libs:material3-navigation"))

add("implementation", libs.findLibrary("androidx.navigation.compose").get())
add("implementation", libs.findLibrary("kotlinx.collections.immutable").get())
add("implementation", libs.findLibrary("androidx.hilt.navigation.compose").get())
add("implementation", libs.findLibrary("androidx.lifecycle.runtimeCompose").get())
add("implementation", libs.findLibrary("androidx.lifecycle.viewModelCompose").get())
add("implementation", libs.findLibrary("androidx.tracing.ktx").get())

add("implementation", platform(libs.findLibrary("koin-bom").get()))
add("implementation", libs.findLibrary("koin-android").get())
add("implementation", libs.findLibrary("koin.androidx.compose").get())

add("implementation", libs.findLibrary("koin.android").get())
add("implementation", libs.findLibrary("koin.androidx.navigation").get())
add("implementation", libs.findLibrary("koin.androidx.compose").get())
add("implementation", libs.findLibrary("koin.core.viewmodel").get())

add("androidTestImplementation", libs.findLibrary("androidx.lifecycle.runtimeTesting").get())

add("testImplementation", kotlin("test"))
add("testImplementation", libs.findLibrary("hilt.android.testing").get())

add("testImplementation", libs.findLibrary("koin.test").get())
add("testImplementation", libs.findLibrary("koin.test.junit4").get())

add("debugImplementation", libs.findLibrary("androidx.compose.ui.test.manifest").get())
add("androidTestImplementation", libs.findLibrary("androidx.navigation.testing").get())
add("androidTestImplementation", libs.findLibrary("androidx.compose.ui.test").get())
add("androidTestImplementation", libs.findLibrary("hilt.android.testing").get())
add("androidTestImplementation", libs.findLibrary("androidx.lifecycle.runtimeTesting").get())
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
apply("mifos.detekt.plugin")
apply("mifos.spotless.plugin")
apply("mifos.ktlint.plugin")
apply("mifospay.android.koin")
}

extensions.configure<LibraryExtension> {
Expand All @@ -32,10 +33,12 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
// so resources inside ":core:module1" must be prefixed with "core_module1_"
resourcePrefix = path.split("""\W""".toRegex()).drop(1).distinct().joinToString(separator = "_").lowercase() + "_"
}

extensions.configure<LibraryAndroidComponentsExtension> {
configurePrintApksTask(this)
disableUnnecessaryAndroidTests(target)
}

dependencies {
add("testImplementation", kotlin("test"))
add("implementation", libs.findLibrary("androidx.tracing.ktx").get())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.mifospay.libs

class CMPFeatureConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply {
apply("mifospay.kmp.library")
apply("mifospay.kmp.inject")
apply("org.jetbrains.kotlin.plugin.compose")
apply("org.jetbrains.compose")
}

dependencies {
add("commonMainImplementation", project(":core:ui"))
add("commonMainImplementation", project(":core:designsystem"))
add("commonMainImplementation", project(":core:data"))
add("commonMainImplementation", libs.findLibrary("jetbrains.compose.viewmodel").get())
add("commonMainImplementation", libs.findLibrary("jetbrains.compose.navigation").get())
add("commonMainImplementation", libs.findLibrary("kotlinx.collections.immutable").get())

add("androidMainImplementation", project(":libs:material3-navigation"))

add("androidMainImplementation", libs.findLibrary("androidx.lifecycle.runtimeCompose").get())
add("androidMainImplementation", libs.findLibrary("androidx.lifecycle.viewModelCompose").get())
add("androidMainImplementation", libs.findLibrary("androidx.tracing.ktx").get())

add("androidMainImplementation", platform(libs.findLibrary("koin-bom").get()))
add("androidMainImplementation", libs.findLibrary("koin-android").get())
add("androidMainImplementation", libs.findLibrary("koin.androidx.compose").get())

add("androidMainImplementation", libs.findLibrary("koin.android").get())
add("androidMainImplementation", libs.findLibrary("koin.androidx.navigation").get())
add("androidMainImplementation", libs.findLibrary("koin.androidx.compose").get())
add("androidMainImplementation", libs.findLibrary("koin.core.viewmodel").get())

add("androidTestImplementation", libs.findLibrary("koin.test.junit4").get())

add("androidDebugImplementation", libs.findLibrary("androidx.compose.ui.test.manifest").get())
add("androidInstrumentedTestImplementation", libs.findLibrary("androidx.navigation.testing").get())
add("androidInstrumentedTestImplementation", libs.findLibrary("androidx.compose.ui.test").get())
add("androidInstrumentedTestImplementation", libs.findLibrary("androidx.lifecycle.runtimeTesting").get())
add("androidInstrumentedTestImplementation", libs.findLibrary("androidx.test.core").get())
add("androidInstrumentedTestImplementation", libs.findLibrary("androidx.test.ext").get())
add("androidInstrumentedTestImplementation", libs.findLibrary("androidx.test.junit").get())
add("androidInstrumentedTestImplementation", libs.findLibrary("androidx.test.runner").get())
add("androidInstrumentedTestImplementation", libs.findLibrary("androidx.test.espresso.core").get())
}
}
}
}
40 changes: 40 additions & 0 deletions build-logic/convention/src/main/kotlin/KMPKoinConventionPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import com.google.devtools.ksp.gradle.KspExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.mifospay.libs


class KMPKoinConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.google.devtools.ksp")
}

dependencies {
val bom = libs.findLibrary("koin-bom").get()
add("commonMainImplementation", platform(bom))
add("commonMainImplementation", libs.findLibrary("koin.core").get())

add("commonMainImplementation", libs.findLibrary("koin.annotations").get())
add("kspCommonMainMetadata", libs.findLibrary("koin.ksp.compiler").get())
add("ksp", libs.findLibrary("koin.ksp.compiler").get())
// add("kspWasmJs", libs.findLibrary("koin.ksp.compiler").get())
// add("kspJvm", libs.findLibrary("koin.ksp.compiler").get())
// add("kspIosX64", libs.findLibrary("koin.ksp.compiler").get())
// add("kspIosArm64", libs.findLibrary("koin.ksp.compiler").get())
// add("kspIosSimulatorArm64", libs.findLibrary("koin.ksp.compiler").get())

add("commonTestImplementation", libs.findLibrary("koin.test").get())
}

extensions.configure<KspExtension> {
arg("KOIN_CONFIG_CHECK","true")
arg("USE_COMPOSE_VIEWMODEL", "false")
arg("KOIN_USE_COMPOSE_VIEWMODEL", "true")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

import com.android.build.gradle.LibraryExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.mifospay.configureFlavors
import org.mifospay.configureKotlinAndroid
import org.mifospay.configureKotlinMultiplatform
import org.mifospay.libs

class KMPLibraryConventionPlugin: Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.library")
apply("org.jetbrains.kotlin.multiplatform")
apply("mifospay.kmp.koin")
apply("mifos.detekt.plugin")
apply("mifos.spotless.plugin")
apply("mifos.ktlint.plugin")
}

configureKotlinMultiplatform()

extensions.configure<LibraryExtension> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 34
configureFlavors(this)
// The resource prefix is derived from the module name,
// so resources inside ":core:module1" must be prefixed with "core_module1_"
resourcePrefix = path.split("""\W""".toRegex()).drop(1).distinct().joinToString(separator = "_").lowercase() + "_"
}

dependencies {
add("commonTestImplementation", libs.findLibrary("kotlin.test").get())
add("commonTestImplementation", libs.findLibrary("kotlinx.coroutines.test").get())
}
}
}
}
36 changes: 36 additions & 0 deletions build-logic/convention/src/main/kotlin/KoinConventionPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import com.google.devtools.ksp.gradle.KspExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.mifospay.libs


class KoinConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.google.devtools.ksp")
}

dependencies {
val bom = libs.findLibrary("koin-bom").get()
add("implementation", platform(bom))
add("implementation", libs.findLibrary("koin.core").get())

add("implementation", libs.findLibrary("koin.annotations").get())
add("ksp", libs.findLibrary("koin.ksp.compiler").get())


add("testImplementation", libs.findLibrary("koin.test").get())
add("testImplementation", libs.findLibrary("koin.test.junit4").get())
}

extensions.configure<KspExtension> {
arg("KOIN_CONFIG_CHECK","true")
arg("USE_COMPOSE_VIEWMODEL", "false")
arg("KOIN_USE_COMPOSE_VIEWMODEL", "true")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.mifospay.libs

class KotlinInjectConventionPlugin: Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.google.devtools.ksp")
}
dependencies {
add("kspCommonMainMetadata", libs.findLibrary("kotlin.inject.compiler.ksp").get())
add("commonMainImplementation", libs.findLibrary("kotlin.inject.runtime.kmp").get())
// KSP will eventually have better multiplatform support and we'll be able to simply have
// `ksp libs.kotlinInject.compiler` in the dependencies block of each source set
// https://github.com/google/ksp/pull/1021
add("kspIosX64", libs.findLibrary("kotlin.inject.compiler.ksp").get())
add("kspIosArm64", libs.findLibrary("kotlin.inject.compiler.ksp").get())
add("kspIosSimulatorArm64", libs.findLibrary("kotlin.inject.compiler.ksp").get())
// add("kspWasmJs", libs.findLibrary("kotlin.inject.compiler.ksp").get())
add("kspAndroid", libs.findLibrary("kotlin.inject.compiler.ksp").get())
add("kspJvm", libs.findLibrary("kotlin.inject.compiler.ksp").get())
add("kspMacosX64", libs.findLibrary("kotlin.inject.compiler.ksp").get())
add("kspMacosArm64", libs.findLibrary("kotlin.inject.compiler.ksp").get())
}
}
}
}
Loading

0 comments on commit 348ec06

Please sign in to comment.