Skip to content

Commit

Permalink
Merge pull request #6 from boranfrkn/ConventionPluginExtensions
Browse files Browse the repository at this point in the history
created extensions for convention plugins
  • Loading branch information
boranfrkn authored Aug 18, 2023
2 parents 3e1582d + 02b6fcb commit 6191910
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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<VersionCatalogsExtension>().named("libs")

fun Project.kapt(block: KaptExtension.() -> Unit): Unit =
(this as ExtensionAware).extensions.configure("kapt", block)
private fun Project.findLibrary(libName: String): Provider<MinimalExternalModuleDependency> {
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))
)
}
}
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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")
}
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 6191910

Please sign in to comment.