From 02b6fcb0124f9f44900d28cf79258635536d2663 Mon Sep 17 00:00:00 2001 From: boranfrkn Date: Fri, 18 Aug 2023 08:41:14 +0300 Subject: [PATCH] created extensions for convention plugins --- .../com/furkanboran/build_logic/Extensions.kt | 33 ++++++++++++++++--- .../build_logic/compose-convention.gradle.kts | 16 +++++---- .../build_logic/hilt-convention.gradle.kts | 7 ++-- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/build-logic/src/main/java/com/furkanboran/build_logic/Extensions.kt b/build-logic/src/main/java/com/furkanboran/build_logic/Extensions.kt index 3ff669b..06d00f1 100644 --- a/build-logic/src/main/java/com/furkanboran/build_logic/Extensions.kt +++ b/build-logic/src/main/java/com/furkanboran/build_logic/Extensions.kt @@ -1,14 +1,37 @@ package com.furkanboran.build_logic import org.gradle.api.Project +import org.gradle.api.artifacts.MinimalExternalModuleDependency import org.gradle.api.artifacts.VersionCatalog import org.gradle.api.artifacts.VersionCatalogsExtension -import org.gradle.api.plugins.ExtensionAware +import org.gradle.api.provider.Provider +import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.getByType -import org.jetbrains.kotlin.gradle.plugin.KaptExtension -val Project.libs +private val Project.libs get(): VersionCatalog = extensions.getByType().named("libs") -fun Project.kapt(block: KaptExtension.() -> Unit): Unit = - (this as ExtensionAware).extensions.configure("kapt", block) \ No newline at end of file +private fun Project.findLibrary(libName: String): Provider { + return libs.findLibrary(libName).get() +} + +fun Project.addImplementation(libName: String) { + dependencies.add("implementation", findLibrary(libName)) +} + +fun Project.addDebugImplementation(libName: String) { + dependencies.add("debugImplementation", findLibrary(libName)) +} + +fun Project.addKaptImplementation(libName: String) { + dependencies.add("kapt", findLibrary(libName)) +} + +fun Project.addPlatformImplementation(libName: String) { + dependencies { + dependencies.add( + "implementation", + platform(findLibrary(libName)) + ) + } +} diff --git a/build-logic/src/main/java/com/furkanboran/build_logic/compose-convention.gradle.kts b/build-logic/src/main/java/com/furkanboran/build_logic/compose-convention.gradle.kts index bfaf805..635ea51 100644 --- a/build-logic/src/main/java/com/furkanboran/build_logic/compose-convention.gradle.kts +++ b/build-logic/src/main/java/com/furkanboran/build_logic/compose-convention.gradle.kts @@ -1,4 +1,6 @@ -import com.furkanboran.build_logic.libs +import com.furkanboran.build_logic.addDebugImplementation +import com.furkanboran.build_logic.addImplementation +import com.furkanboran.build_logic.addPlatformImplementation plugins { id("library-convention") @@ -17,10 +19,10 @@ android { } dependencies { - add("implementation", platform(libs.findLibrary("composeBom").get())) - add("implementation", libs.findLibrary("ui").get()) - add("implementation", libs.findLibrary("uiGraphics").get()) - add("implementation", libs.findLibrary("uiToolingPreview").get()) - add("implementation", libs.findLibrary("material3").get()) - add("debugImplementation", libs.findLibrary("uiTooling").get()) + addPlatformImplementation("composeBom") + addImplementation("ui") + addImplementation("uiGraphics") + addImplementation("uiToolingPreview") + addImplementation("material3") + addDebugImplementation("uiTooling") } diff --git a/build-logic/src/main/java/com/furkanboran/build_logic/hilt-convention.gradle.kts b/build-logic/src/main/java/com/furkanboran/build_logic/hilt-convention.gradle.kts index 1cf04c8..a100676 100644 --- a/build-logic/src/main/java/com/furkanboran/build_logic/hilt-convention.gradle.kts +++ b/build-logic/src/main/java/com/furkanboran/build_logic/hilt-convention.gradle.kts @@ -1,10 +1,11 @@ -import com.furkanboran.build_logic.libs +import com.furkanboran.build_logic.addImplementation +import com.furkanboran.build_logic.addKaptImplementation plugins { kotlin("kapt") } dependencies { - add("implementation", libs.findLibrary("hiltAndroid").get()) - add("kapt", libs.findLibrary("hiltCompiler").get()) + addImplementation("hiltAndroid") + addKaptImplementation("hiltCompiler") } \ No newline at end of file