Skip to content

Commit

Permalink
Merge pull request #505 from nimblehq/feature/kmm-support-dependencies
Browse files Browse the repository at this point in the history
[#512] [KMM Support] Update Kotlin DSL build dependencies & plugins configuration
  • Loading branch information
ryan-conway authored Oct 2, 2023
2 parents ffbfa73 + bf30edc commit b50eac6
Show file tree
Hide file tree
Showing 14 changed files with 259 additions and 167 deletions.
6 changes: 0 additions & 6 deletions template-compose/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,8 @@ captures/
*.iml
.idea/*

# Keystore files
secret/

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google services
google-services.json

# Keystore
config/release.keystore
3 changes: 3 additions & 0 deletions template-compose/app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/build

# Google services
google-services.json
122 changes: 63 additions & 59 deletions template-compose/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
plugins {
id("com.android.application")

id("kotlin-android")
id("kotlin-kapt")
id("kotlin-parcelize")

id("dagger.hilt.android.plugin")
id("org.jetbrains.kotlinx.kover")
id(Plugins.ANDROID_APPLICATION)
id(Plugins.KOTLIN_ANDROID)
id(Plugins.KOTLIN_KAPT)
id(Plugins.KOTLIN_PARCELIZE)
id(Plugins.HILT_ANDROID)
id(Plugins.KOVER)
}

val keystoreProperties = rootDir.loadGradleProperties("signing.properties")
Expand All @@ -20,57 +18,57 @@ val getVersionCode: () -> Int = {

android {
signingConfigs {
create(BuildType.RELEASE) {
create(BuildTypes.RELEASE) {
// Remember to edit signing.properties to have the correct info for release build.
storeFile = file("../config/release.keystore")
storePassword = keystoreProperties.getProperty("KEYSTORE_PASSWORD") as String
keyPassword = keystoreProperties.getProperty("KEY_PASSWORD") as String
keyAlias = keystoreProperties.getProperty("KEY_ALIAS") as String
}

getByName(BuildType.DEBUG) {
getByName(BuildTypes.DEBUG) {
storeFile = file("../config/debug.keystore")
storePassword = "oQ4mL1jY2uX7wD8q"
keyAlias = "debug-key-alias"
keyPassword = "oQ4mL1jY2uX7wD8q"
}
}

compileSdk = Versions.ANDROID_COMPILE_SDK_VERSION
compileSdk = Versions.ANDROID_COMPILE_SDK
defaultConfig {
applicationId = "co.nimblehq.template.compose"
minSdk = Versions.ANDROID_MIN_SDK_VERSION
targetSdk = Versions.ANDROID_TARGET_SDK_VERSION
minSdk = Versions.ANDROID_MIN_SDK
targetSdk = Versions.ANDROID_TARGET_SDK
versionCode = getVersionCode()
versionName = Versions.ANDROID_VERSION_NAME
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
getByName(BuildType.RELEASE) {
getByName(BuildTypes.RELEASE) {
isMinifyEnabled = true
isDebuggable = false
isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
signingConfig = signingConfigs[BuildType.RELEASE]
signingConfig = signingConfigs[BuildTypes.RELEASE]
buildConfigField("String", "BASE_API_URL", "\"https://jsonplaceholder.typicode.com/\"")
}

getByName(BuildType.DEBUG) {
getByName(BuildTypes.DEBUG) {
// For quickly testing build with proguard, enable this
isMinifyEnabled = false
signingConfig = signingConfigs[BuildType.DEBUG]
signingConfig = signingConfigs[BuildTypes.DEBUG]
buildConfigField("String", "BASE_API_URL", "\"https://jsonplaceholder.typicode.com/\"")
}
}

flavorDimensions += Flavor.DIMENSION_VERSION
flavorDimensions += Flavors.DIMENSION_VERSION
productFlavors {
create(Flavor.STAGING) {
create(Flavors.STAGING) {
applicationIdSuffix = ".staging"
}

create(Flavor.PRODUCTION) {}
create(Flavors.PRODUCTION) {}
}

sourceSets["test"].resources {
Expand All @@ -87,7 +85,7 @@ android {
}

composeOptions {
kotlinCompilerExtensionVersion = Versions.COMPOSE_COMPILER_VERSION
kotlinCompilerExtensionVersion = Versions.COMPOSE_COMPILER
}

buildFeatures {
Expand Down Expand Up @@ -115,60 +113,66 @@ kapt {
}

dependencies {
implementation(project(Module.DATA))
implementation(project(Module.DOMAIN))
implementation(project(Modules.DATA))
implementation(project(Modules.DOMAIN))

implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

implementation("androidx.core:core-ktx:${Versions.ANDROIDX_CORE_KTX_VERSION}")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:${Versions.ANDROIDX_LIFECYCLE_VERSION}")
implementation("androidx.lifecycle:lifecycle-runtime-compose:${Versions.ANDROIDX_LIFECYCLE_VERSION}")

implementation(platform("androidx.compose:compose-bom:${Versions.COMPOSE_BOM_VERSION}"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-tooling")
implementation("androidx.compose.foundation:foundation")
implementation("androidx.compose.material:material")

implementation("androidx.datastore:datastore-preferences:${Versions.ANDROIDX_DATASTORE_PREFERENCES_VERSION}")

implementation("androidx.navigation:navigation-compose:${Versions.COMPOSE_NAVIGATION_VERSION}")
implementation("com.google.accompanist:accompanist-permissions:${Versions.ACCOMPANIST_PERMISSIONS_VERSION}")

implementation("com.google.dagger:hilt-android:${Versions.HILT_VERSION}")
implementation("androidx.hilt:hilt-navigation-compose:${Versions.HILT_NAVIGATION_COMPOSE_VERSION}")
with(Dependencies.AndroidX) {
implementation(CORE_KTX)
implementation(LIFECYCLE_RUNTIME_KTX)
implementation(LIFECYCLE_RUNTIME_COMPOSE)
implementation(DATASTORE_PREFERENCES)
}

implementation("com.jakewharton.timber:timber:${Versions.TIMBER_LOG_VERSION}")
with(Dependencies.Compose) {
implementation(platform(BOM))
implementation(UI)
implementation(UI_TOOLING)
implementation(MATERIAL)
implementation(NAVIGATION)

implementation("com.github.nimblehq:android-common-ktx:${Versions.ANDROID_COMMON_KTX_VERSION}")
implementation(ACCOMPANIST_PERMISSIONS)
}

implementation("org.jetbrains.kotlin:kotlin-stdlib:${Versions.KOTLIN_VERSION}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.KOTLINX_COROUTINES_VERSION}")
with(Dependencies.Hilt) {
implementation(ANDROID)
implementation(NAVIGATION_COMPOSE)
kapt(COMPILER)
}

kapt("com.google.dagger:hilt-compiler:${Versions.HILT_VERSION}")
with(Dependencies.Log) {
implementation(TIMBER)

debugImplementation("com.github.chuckerteam.chucker:library:${Versions.CHUCKER_VERSION}")
releaseImplementation("com.github.chuckerteam.chucker:library-no-op:${Versions.CHUCKER_VERSION}")
debugImplementation(CHUCKER)
releaseImplementation(CHUCKER_NO_OP)
}

// Unit test
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.KOTLINX_COROUTINES_VERSION}")
testImplementation("io.kotest:kotest-assertions-core:${Versions.TEST_KOTEST_VERSION}")
testImplementation("junit:junit:${Versions.TEST_JUNIT_VERSION}")
testImplementation("io.mockk:mockk:${Versions.TEST_MOCKK_VERSION}")
testImplementation("app.cash.turbine:turbine:${Versions.TEST_TURBINE_VERSION}")
with(Dependencies.Util) {
implementation(COMMON_KTX)
}

// UI test with Robolectric
testImplementation(platform("androidx.compose:compose-bom:${Versions.COMPOSE_BOM_VERSION}"))
testImplementation("androidx.compose.ui:ui-test-junit4")
testImplementation("org.robolectric:robolectric:${Versions.TEST_ROBOLECTRIC_VERSION}")
with(Dependencies.Test) {
// Unit test
testImplementation(COROUTINES)
testImplementation(JUNIT)
testImplementation(KOTEST)
testImplementation(MOCKK)
testImplementation(TURBINE)

// UI test with Robolectric
testImplementation(platform(Dependencies.Compose.BOM))
testImplementation(COMPOSE_UI_TEST_JUNIT)
testImplementation(ROBOLECTRIC)
}
}

/*
* Kover configs
*/
dependencies {
kover(project(":data"))
kover(project(":domain"))
kover(project(Modules.DATA))
kover(project(Modules.DOMAIN))
}

koverReport {
Expand Down
16 changes: 8 additions & 8 deletions template-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ buildscript {
}

dependencies {
classpath("com.android.tools.build:gradle:${Versions.BUILD_GRADLE_VERSION}")
classpath("com.google.dagger:hilt-android-gradle-plugin:${Versions.HILT_VERSION}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.KOTLIN_VERSION}")
classpath("com.android.tools.build:gradle:${Versions.GRADLE}")
classpath("com.google.dagger:hilt-android-gradle-plugin:${Versions.HILT}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.KOTLIN}")
}
}

plugins {
id("io.gitlab.arturbosch.detekt").version(Versions.DETEKT_VERSION)
id("org.jetbrains.kotlinx.kover").version(Versions.KOVER_VERSION)
id(Plugins.DETEKT).version(Versions.DETEKT)
id(Plugins.KOVER).version(Versions.KOVER)
}

allprojects {
Expand All @@ -30,7 +30,7 @@ tasks.register("clean", Delete::class) {
}

detekt {
toolVersion = Versions.DETEKT_VERSION
toolVersion = Versions.DETEKT

source = files(
"app/src/main/java",
Expand All @@ -46,8 +46,8 @@ detekt {
debug = false
ignoreFailures = false

ignoredBuildTypes = listOf("release")
ignoredFlavors = listOf("production")
ignoredBuildTypes = listOf(BuildTypes.RELEASE)
ignoredFlavors = listOf(Flavors.PRODUCTION)
}

tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
Expand Down
2 changes: 1 addition & 1 deletion template-compose/buildSrc/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
build/
/build
4 changes: 4 additions & 0 deletions template-compose/buildSrc/src/main/java/BuildTypes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object BuildTypes {
const val DEBUG = "debug"
const val RELEASE = "release"
}
15 changes: 0 additions & 15 deletions template-compose/buildSrc/src/main/java/Configurations.kt

This file was deleted.

71 changes: 71 additions & 0 deletions template-compose/buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
object Dependencies {
object AndroidX {
const val CORE_KTX = "androidx.core:core-ktx:${Versions.CORE_KTX}"
const val LIFECYCLE_RUNTIME_KTX = "androidx.lifecycle:lifecycle-runtime-ktx:${Versions.LIFECYCLE}"
const val LIFECYCLE_RUNTIME_COMPOSE = "androidx.lifecycle:lifecycle-runtime-compose:${Versions.LIFECYCLE}"

const val DATASTORE_PREFERENCES = "androidx.datastore:datastore-preferences:${Versions.DATASTORE_PREFERENCES}"
const val SECURITY_CRYPTO = "androidx.security:security-crypto:${Versions.SECURITY_CRYPTO}"
}

object Compose {
const val BOM = "androidx.compose:compose-bom:${Versions.COMPOSE_BOM}"
const val UI = "androidx.compose.ui:ui"
const val UI_GRAPHICS = "androidx.compose.ui:ui-graphics"
const val UI_TOOLING = "androidx.compose.ui:ui-tooling"
const val MATERIAL = "androidx.compose.material:material"
const val NAVIGATION = "androidx.navigation:navigation-compose:${Versions.COMPOSE_NAVIGATION}"

const val ACCOMPANIST_PERMISSIONS = "com.google.accompanist:accompanist-permissions:${Versions.ACCOMPANIST}"
}

object Hilt {
const val ANDROID = "com.google.dagger:hilt-android:${Versions.HILT}"
const val NAVIGATION_COMPOSE = "androidx.hilt:hilt-navigation-compose:${Versions.HILT_NAVIGATION_COMPOSE}"
const val COMPILER = "com.google.dagger:hilt-compiler:${Versions.HILT}"

const val JAVAX_INJECT = "javax.inject:javax.inject:${Versions.JAVAX_INJECT}"
}

object Kotlin {
const val COROUTINES_CORE = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.KOTLIN_COROUTINES}"
}

object Log {
const val TIMBER = "com.jakewharton.timber:timber:${Versions.TIMBER}"

const val CHUCKER = "com.github.chuckerteam.chucker:library:${Versions.CHUCKER}"
const val CHUCKER_NO_OP = "com.github.chuckerteam.chucker:library-no-op:${Versions.CHUCKER}"
}

object Network {
const val RETROFIT = "com.squareup.retrofit2:retrofit:${Versions.RETROFIT}"
const val RETROFIT_CONVERTER_MOSHI = "com.squareup.retrofit2:converter-moshi:${Versions.RETROFIT}"

const val OKHTTP = "com.squareup.okhttp3:okhttp:${Versions.OKHTTP}"
const val OKHTTP_LOGGING_INTERCEPTOR = "com.squareup.okhttp3:logging-interceptor:${Versions.OKHTTP}"

const val MOSHI = "com.squareup.moshi:moshi:${Versions.MOSHI}"
const val MOSHI_ADAPTERS = "com.squareup.moshi:moshi-adapters:${Versions.MOSHI}"
const val MOSHI_KOTLIN = "com.squareup.moshi:moshi-kotlin:${Versions.MOSHI}"
}

object Util {
const val COMMON_KTX = "com.github.nimblehq:android-common-ktx:${Versions.COMMON_KTX}"
}

object Test {
const val COMPOSE_UI_TEST_JUNIT = "androidx.compose.ui:ui-test-junit4"
const val COROUTINES = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.KOTLIN_COROUTINES}"

const val JUNIT = "junit:junit:${Versions.JUNIT}"

const val KOTEST = "io.kotest:kotest-assertions-core:${Versions.KOTEST}"
const val MOCKK = "io.mockk:mockk:${Versions.MOCKK}"

const val ROBOLECTRIC = "org.robolectric:robolectric:${Versions.ROBOLECTRIC}"

const val TEST_CORE = "androidx.test:core:${Versions.CORE}"
const val TURBINE = "app.cash.turbine:turbine:${Versions.TURBINE}"
}
}
5 changes: 5 additions & 0 deletions template-compose/buildSrc/src/main/java/Flavors.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Flavors {
const val PRODUCTION = "production"
const val STAGING = "staging"
const val DIMENSION_VERSION = "version"
}
4 changes: 4 additions & 0 deletions template-compose/buildSrc/src/main/java/Modules.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Modules {
const val DATA = ":data"
const val DOMAIN = ":domain"
}
16 changes: 16 additions & 0 deletions template-compose/buildSrc/src/main/java/Plugins.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
object Plugins {
const val ANDROID_APPLICATION = "com.android.application"
const val ANDROID_LIBRARY = "com.android.library"
const val JAVA_LIBRARY = "java-library"

const val DETEKT = "io.gitlab.arturbosch.detekt"

const val HILT_ANDROID = "com.google.dagger.hilt.android"

const val KOTLIN = "kotlin" // or a longer alias "org.jetbrains.kotlin.jvm"
const val KOTLIN_ANDROID = "kotlin-android" // or a longer alias "org.jetbrains.kotlin.android"
const val KOTLIN_KAPT = "kotlin-kapt"
const val KOTLIN_PARCELIZE = "kotlin-parcelize"

const val KOVER = "org.jetbrains.kotlinx.kover"
}
Loading

0 comments on commit b50eac6

Please sign in to comment.