Skip to content

Commit

Permalink
MIFOSAC-323 KMP setup
Browse files Browse the repository at this point in the history
  • Loading branch information
itsPronay committed Dec 31, 2024
1 parent 5f44c46 commit 13d8420
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 6 deletions.
16 changes: 15 additions & 1 deletion build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies {
compileOnly(libs.firebase.crashlytics.gradlePlugin)
compileOnly(libs.firebase.performance.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
// compileOnly(libs.compose.gradlePlugin)
compileOnly(libs.compose.gradlePlugin)
compileOnly(libs.ksp.gradlePlugin)
compileOnly(libs.room.gradlePlugin)
compileOnly(libs.detekt.gradlePlugin)
Expand Down Expand Up @@ -118,5 +118,19 @@ gradlePlugin {
implementationClass = "MifosGitHooksConventionPlugin"
description = "Installs git hooks for the project"
}

// KMP & CMP Plugins
register("cmpFeature") {
id = "mifos.cmp.feature"
implementationClass = "CMPFeatureConventionPlugin"
}
register("kmpKoin") {
id = "mifos.kmp.koin"
implementationClass = "KMPKoinConventionPlugin"
}
register("kmpLibrary") {
id = "mifos.kmp.library"
implementationClass = "KMPLibraryConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AndroidApplicationComposeConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
apply(plugin = "com.android.application")
// apply(plugin = "org.jetbrains.kotlin.plugin.compose")
apply(plugin = "org.jetbrains.kotlin.plugin.compose")

val extension = extensions.getByType<ApplicationExtension>()
configureAndroidCompose(extension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AndroidLibraryComposeConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
apply(plugin = "com.android.library")
// apply(plugin = "org.jetbrains.kotlin.plugin.compose")
apply(plugin = "org.jetbrains.kotlin.plugin.compose")

val extension = extensions.getByType<LibraryExtension>()
configureAndroidCompose(extension)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.mifos.libs

/**
* Created by Pronay Sarker on 30/12/2024 (6:04 PM)
*/
class CMPFeatureConventionPlugin : Plugin<Project> {

override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("mifos.kmp.libray")
apply("mifos.kmp.koin")
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:testing"))
add("commonMainImplementation", project(":core:data"))

add("commonMainImplementation", libs.findLibrary("koin.compose").get())
add("commonMainImplementation", libs.findLibrary("koin.compose.viewmodel").get())

add("commonMainImplementation", libs.findLibrary("jb.composeRuntime").get())
add("commonMainImplementation", libs.findLibrary("jb.composeViewmodel").get())
add("commonMainImplementation", libs.findLibrary("jb.lifecycleViewmodel").get())
add("commonMainImplementation", libs.findLibrary("jb.lifecycleViewmodelSavedState").get())
add("commonMainImplementation", libs.findLibrary("jb.savedstate").get())
add("commonMainImplementation", libs.findLibrary("jb.bundle").get())
add("commonMainImplementation", libs.findLibrary("jb.composeNavigation").get())
add("commonMainImplementation", libs.findLibrary("kotlinx.collections.immutable").get())

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("androidInstrumentedTestImplementation", libs.findLibrary("androidx.navigation.testing").get())
add("androidInstrumentedTestImplementation", libs.findLibrary("androidx.compose.ui.test").get())
add("androidInstrumentedTestImplementation", libs.findLibrary("androidx.lifecycle.runtimeTesting").get())
}
}
}
}
28 changes: 28 additions & 0 deletions build-logic/convention/src/main/kotlin/KMPCoinConventionLibrary.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.mifos.libs

/**
* Created by Pronay Sarker on 31/12/2024 (7:29 AM)
*/
class KMPCoinConventionLibrary : 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("commonTestImplementation", libs.findLibrary("koin.test").get())
}
}
}
}

28 changes: 28 additions & 0 deletions build-logic/convention/src/main/kotlin/KMPKoinConventionPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.mifos.libs

/**
* Created by Pronay Sarker on 30/12/2024 (7:30 PM)
*/
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("commonTestImplementation", libs.findLibrary("koin.test").get())
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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.mifos.configureFlavors
import org.mifos.configureKotlinAndroid
import org.mifos.configureKotlinMultiplatform
import org.mifos.libs
/**
* Created by Pronay Sarker on 30/12/2024 (7:33 PM)
*/
class KMPLibraryConventionPlugin : Plugin<Project> {

override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.library")
apply("org.jetbrains.kotlin.multiplatform")
apply("mifos.kmp.koin")
apply("mifos.detekt.plugin")
apply("mifos.spotless.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())
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.mifos

import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension


@OptIn(ExperimentalWasmDsl::class, ExperimentalKotlinGradlePluginApi::class)
internal fun Project.configureKotlinMultiplatform() {
extensions.configure<KotlinMultiplatformExtension> {
applyDefaultHierarchyTemplate()

jvm("desktop")
androidTarget()
iosSimulatorArm64()
iosX64()
iosArm64()
js(IR) {
this.nodejs()
binaries.executable()
}
wasmJs() {
browser()
nodejs()
}

compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
}
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ plugins {
alias(libs.plugins.detekt) apply false
alias(libs.plugins.spotless) apply false
alias(libs.plugins.ktlint) apply false

//Multiplatform Plugins
alias(libs.plugins.jetbrainsCompose) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.wire) apply false
alias(libs.plugins.ktrofit) apply false
}
5 changes: 5 additions & 0 deletions compose_compiler_config.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This file contains classes (with possible wildcards) that the Compose Compiler will treat as stable.
// It allows us to define classes that our not part of our codebase without wrapping them in a stable class.
// For more information, check https://developer.android.com/jetpack/compose/performance/stability/fix#configuration-file

java.time.ZoneOffset
4 changes: 4 additions & 0 deletions core/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ dependencies {

androidTestImplementation(libs.androidx.compose.ui.test)
androidTestImplementation(projects.core.testing)
}

composeCompiler {
stabilityConfigurationFile = rootProject.layout.projectDirectory.file("compose_compiler_config.conf")
}
21 changes: 18 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ androidDesugarJdkLibs = "2.0.4"
androidIconifyMaterial = "2.2.2"
androidJob = "1.2.6"
androidMapsUtils = "0.4.2"
androidGradlePlugin = "8.5.0"
androidGradlePlugin = "8.5.2"
androidTools = "31.6.0"
androidxActivity = "1.8.2"
androidxAppCompat = "1.6.1"
Expand Down Expand Up @@ -66,7 +66,7 @@ jacoco = "0.8.7"
junit4 = "4.13.2"
junitJupiter = "5.8.2"
junitVersion = "1.1.5"
kotlin = "1.9.22"
kotlin = "2.0.21"
kotlinxCoroutines = "1.7.3"
kotlinxCoroutinesCoreVersion = "1.5.1"
kotlinxCoroutinesRx2 = "1.5.1"
Expand Down Expand Up @@ -131,6 +131,14 @@ truthVersion = '1.1.5'
runtimeLivedata = "1.6.8"
appcompat = "1.7.0"

# Ktor & Ktorfit
ktorfit = "2.2.0"

# CMP Libraries
compose-plugin = "1.7.0-rc01"
wire = "5.0.0"
coil-cmp = "3.0.4"

[libraries]
# AndroidX Libraries
accompanist-drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version.ref = "accompanistDrawablepainter" }
Expand Down Expand Up @@ -415,7 +423,6 @@ kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-kapt = { id = "kotlin-kapt", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-parcelize = { id = "kotlin-parcelize", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
protobuf = { id = "com.google.protobuf", version.ref = "protobufPlugin" }
realm = { id = "io.realm.kotlin", version.ref = "realmVersion" }
secrets = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "secrets" }
Expand All @@ -424,6 +431,14 @@ ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotlessVersion" }
dependencyGuard = { id = "com.dropbox.dependency-guard", version.ref = "dependencyGuard" }

# KMP & CMP
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
ktrofit = { id = "de.jensklingenberg.ktorfit", version.ref = "ktorfit" }
wire = { id = "com.squareup.wire", version.ref = "wire" }

# Plugins defined by this project
mifos-android-application = { id = "mifos.android.application", version = "unspecified" }
mifos-android-application-flavors = { id = "mifos.android.application.flavors", version = "unspecified" }
Expand Down
4 changes: 4 additions & 0 deletions libs/mifos-passcode/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ dependencies {
implementation(libs.androidx.hilt.navigation.compose)

}

composeCompiler {
stabilityConfigurationFile = rootProject.layout.projectDirectory.file("compose_compiler_config.conf")
}

0 comments on commit 13d8420

Please sign in to comment.