From 2f7917d134e9140fafb72feb09fd1124f43315b0 Mon Sep 17 00:00:00 2001 From: lihenggui Date: Fri, 15 Nov 2024 14:50:23 -0800 Subject: [PATCH] Add shorthand syntax for adding dependencies in Gradle Kotlin DSL --- .../kotlin/CmpApplicationConventionPlugin.kt | 19 ++++++------ .../main/kotlin/CmpFeatureConventionPlugin.kt | 29 ++++++++++--------- .../main/kotlin/JvmLibraryConventionPlugin.kt | 2 +- .../main/kotlin/KmpLibraryConventionPlugin.kt | 6 ++-- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/CmpApplicationConventionPlugin.kt b/build-logic/convention/src/main/kotlin/CmpApplicationConventionPlugin.kt index 926fb485b..978e24ae1 100644 --- a/build-logic/convention/src/main/kotlin/CmpApplicationConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/CmpApplicationConventionPlugin.kt @@ -56,17 +56,18 @@ class CmpApplicationConventionPlugin : Plugin { } dependencies { - add("commonMainImplementation", project(":core:ui")) - add("commonMainImplementation", project(":core:designsystem")) - add("commonMainImplementation", libs.findLibrary("jetbrains.compose.viewmodel").get()) - add("commonMainImplementation", libs.findLibrary("jetbrains.compose.navigation").get()) - add("commonMainImplementation", libs.findLibrary("koin.compose").get()) - add("commonMainImplementation", libs.findLibrary("koin.compose.viewmodel").get()) - add("commonMainImplementation", libs.findLibrary("koin.compose.viewmodel.navigation").get()) + "commonMainImplementation"(project(":core:ui")) + "commonMainImplementation"(project(":core:designsystem")) + "commonMainImplementation"(libs.findLibrary("jetbrains.compose.viewmodel").get()) + "commonMainImplementation"(libs.findLibrary("jetbrains.compose.navigation").get()) + "commonMainImplementation"(libs.findLibrary("koin.compose").get()) + "commonMainImplementation"(libs.findLibrary("koin.compose.viewmodel").get()) + "commonMainImplementation"(libs.findLibrary("koin.compose.viewmodel.navigation").get()) - add("androidMainImplementation", libs.findLibrary("androidx.lifecycle.runtimeCompose").get()) - add("androidMainImplementation", libs.findLibrary("androidx.tracing.ktx").get()) + "androidMainImplementation"(libs.findLibrary("androidx.lifecycle.runtimeCompose").get()) + "androidMainImplementation"(libs.findLibrary("androidx.tracing.ktx").get()) } + } } } diff --git a/build-logic/convention/src/main/kotlin/CmpFeatureConventionPlugin.kt b/build-logic/convention/src/main/kotlin/CmpFeatureConventionPlugin.kt index 1bacd26db..95c7a7246 100644 --- a/build-logic/convention/src/main/kotlin/CmpFeatureConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/CmpFeatureConventionPlugin.kt @@ -43,24 +43,25 @@ class CmpFeatureConventionPlugin : Plugin { } dependencies { - add("commonMainImplementation", project(":core:ui")) - add("commonMainImplementation", project(":core:designsystem")) - add("commonMainImplementation", libs.findLibrary("jetbrains.compose.viewmodel").get()) - add("commonMainImplementation", libs.findLibrary("jetbrains.compose.navigation").get()) + "commonMainImplementation"(project(":core:ui")) + "commonMainImplementation"(project(":core:designsystem")) + "commonMainImplementation"(libs.findLibrary("jetbrains.compose.viewmodel").get()) + "commonMainImplementation"(libs.findLibrary("jetbrains.compose.navigation").get()) "commonMainImplementation"(platform(libs.findLibrary("koin.bom").get())) - add("commonMainImplementation", libs.findLibrary("koin.compose").get()) - add("commonMainImplementation", libs.findLibrary("koin.compose.viewmodel").get()) - add("commonMainImplementation", libs.findLibrary("koin.compose.viewmodel.navigation").get()) + "commonMainImplementation"(libs.findLibrary("koin.compose").get()) + "commonMainImplementation"(libs.findLibrary("koin.compose.viewmodel").get()) + "commonMainImplementation"(libs.findLibrary("koin.compose.viewmodel.navigation").get()) - add("androidMainImplementation", libs.findLibrary("androidx.lifecycle.runtimeCompose").get()) - add("androidMainImplementation", libs.findLibrary("androidx.tracing.ktx").get()) + "androidMainImplementation"(libs.findLibrary("androidx.lifecycle.runtimeCompose").get()) + "androidMainImplementation"(libs.findLibrary("androidx.tracing.ktx").get()) - add("androidInstrumentedTestImplementation", libs.findLibrary("androidx.compose.ui.test").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()) + "androidInstrumentedTestImplementation"(libs.findLibrary("androidx.compose.ui.test").get()) + "androidInstrumentedTestImplementation"(libs.findLibrary("androidx.test.core").get()) + "androidInstrumentedTestImplementation"(libs.findLibrary("androidx.test.ext").get()) + "androidInstrumentedTestImplementation"(libs.findLibrary("androidx.test.junit").get()) + "androidInstrumentedTestImplementation"(libs.findLibrary("androidx.test.runner").get()) } + } } } diff --git a/build-logic/convention/src/main/kotlin/JvmLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/JvmLibraryConventionPlugin.kt index 652409db6..0e5cb45bb 100644 --- a/build-logic/convention/src/main/kotlin/JvmLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/JvmLibraryConventionPlugin.kt @@ -29,7 +29,7 @@ class JvmLibraryConventionPlugin : Plugin { } configureKotlinJvm() dependencies { - add("testImplementation", kotlin("test")) + "testImplementation"(kotlin("test")) } } } diff --git a/build-logic/convention/src/main/kotlin/KmpLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/KmpLibraryConventionPlugin.kt index 9797df939..2c9a33b29 100644 --- a/build-logic/convention/src/main/kotlin/KmpLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/KmpLibraryConventionPlugin.kt @@ -39,9 +39,9 @@ class KmpLibraryConventionPlugin: Plugin { resourcePrefix = path.split("""\W""".toRegex()).drop(1).distinct().joinToString(separator = "_").lowercase() + "_" } dependencies { - add("commonTestImplementation", libs.findLibrary("kotlin.test").get()) - add("commonTestImplementation", libs.findLibrary("turbine").get()) - add("commonTestImplementation", libs.findLibrary("kotlinx.coroutines.test").get()) + "commonTestImplementation"(libs.findLibrary("kotlin.test").get()) + "commonTestImplementation"(libs.findLibrary("turbine").get()) + "commonTestImplementation"(libs.findLibrary("kotlinx.coroutines.test").get()) } } }