Skip to content

Commit

Permalink
gradle refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
stslex committed May 21, 2024
1 parent 94f080a commit cdcfc74
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 25 deletions.
13 changes: 10 additions & 3 deletions build-logic/dependencies/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ plugins {
group = "st.slex.csplashscreen.buildlogic"

dependencies {
implementation(libs.android.gradlePlugin)
implementation(libs.kotlin.gradlePlugin)
implementation(libs.kotlin.serialization)
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.kotlin.serialization)
compileOnly(libs.ksp.gradlePlugin)
compileOnly(libs.room.gradlePlugin)
compileOnly(libs.android.tools.common)
}

gradlePlugin {
Expand All @@ -28,5 +31,9 @@ gradlePlugin {
id = "csplashscreen.android.library"
implementationClass = "AndroidLibraryConventionPlugin"
}
register("roomLibrary"){
id = "csplashscreen.room.library"
implementationClass = "RoomLibraryConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AppExt.currentLibs
import AppExt.findVersionInt
import AppExt.findVersionString
import com.android.build.api.dsl.ApplicationExtension
import com.google.devtools.ksp.gradle.KspExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
Expand Down Expand Up @@ -35,6 +36,10 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
configureSigning(target)
}
}

extensions.configure<KspExtension> {
arg("KOIN_CONFIG_CHECK", "true")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.android.build.gradle.LibraryExtension
import com.google.devtools.ksp.gradle.KspExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
Expand Down Expand Up @@ -36,6 +37,10 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
}
}

extensions.configure<KspExtension> {
arg("KOIN_CONFIG_CHECK", "true")
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
configurations.configureEach {
resolutionStrategy {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import AppExt.currentLibs
import androidx.room.gradle.RoomExtension
import com.google.devtools.ksp.gradle.KspExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies

class RoomLibraryConventionPlugin : Plugin<Project> {

override fun apply(target: Project) {
with(target) {
pluginManager.apply("androidx.room")
pluginManager.apply("com.google.devtools.ksp")

extensions.configure<KspExtension> {
arg("room.generateKotlin", "true")
}

extensions.configure<RoomExtension> {
// The schemas directory contains a schema file for each version of the Room database.
// This is required to enable Room auto migrations.
// See https://developer.android.com/reference/kotlin/androidx/room/AutoMigration.
schemaDirectory("$projectDir/schemas")
}

dependencies {
add("implementation", currentLibs.findLibrary("room.runtime").get())
add("implementation", currentLibs.findLibrary("room.ktx").get())
add("ksp", currentLibs.findLibrary("room.compiler").get())
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,14 @@ internal fun Project.configureKotlinAndroid(
configureKotlin()

dependencies {
add("coreLibraryDesugaring", libs.findLibrary("android-desugarJdkLibs").get())

val ktx = libs.findLibrary("androidx-core-ktx").get()
add("implementation", ktx)

val test = libs.findBundle("test").get()
add("testImplementation", test)

val androidTest = libs.findBundle("android-test").get()
add("androidTestImplementation", androidTest)

val immutableCollection = libs.findLibrary("kotlinx-collections-immutable").get()
add("implementation", immutableCollection)

val coroutines = libs.findLibrary("coroutines").get()
add("implementation", coroutines)

val koinBundle = libs.findBundle("koin").get()
add("implementation", koinBundle)

val koinKsp = libs.findLibrary("koin-ksp").get()
add("ksp", koinKsp)
"coreLibraryDesugaring"(libs.findLibrary("android-desugarJdkLibs").get())
"implementation"(libs.findLibrary("androidx-core-ktx").get())
"testImplementation"(libs.findBundle("test").get())
"androidTestImplementation"(libs.findBundle("android-test").get())
"implementation"(libs.findLibrary("kotlinx-collections-immutable").get())
"implementation"(libs.findLibrary("coroutines").get())
"implementation"(libs.findBundle("koin").get())
"ksp"(libs.findLibrary("koin-ksp").get())
}
}

Expand Down
10 changes: 10 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
androidDesugarJdkLibs = "2.0.4"
kotlin = "1.9.23"
androidGradlePlugin = "8.3.2"
androidTools = "31.4.0"

minSdk = "28"
targetSdk = "34"
Expand Down Expand Up @@ -45,6 +46,9 @@ android-desugarJdkLibs = { module = "com.android.tools:desugar_jdk_libs", versio
android-gradlePlugin = { module = "com.android.tools.build:gradle", version.ref = "androidGradlePlugin" }
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
ksp-gradlePlugin = { group = "com.google.devtools.ksp", name = "com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" }
android-tools-common = { group = "com.android.tools", name = "common", version.ref = "androidTools" }
room-gradlePlugin = { group = "androidx.room", name = "room-gradle-plugin", version.ref = "room" }

kotlinx-collections-immutable = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "immutableCollection" }

Expand Down Expand Up @@ -124,6 +128,12 @@ application = { id = "com.android.application", version.ref = "androidGradlePlug
library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }

convention-application = { id = "csplashscreen.android.application" }
convention-application-compose = { id = "csplashscreen.android.application.compose" }
convention-library = { id = "csplashscreen.android.library" }
convention-library-compose = { id = "csplashscreen.android.library.compose" }
convention-room-library = { id = "csplashscreen.room.library" }

[bundles]
lifecycle = [
"lifecycle-compose",
Expand Down

0 comments on commit cdcfc74

Please sign in to comment.