Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gradle refactor #82

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
plugins {
id("csplashscreen.android.application")
id("csplashscreen.android.application.compose")
alias(libs.plugins.convention.application)
alias(libs.plugins.convention.application.compose)
}

dependencies {
implementation(project(":core:core"))
implementation(project(":core:ui"))
implementation(project(":core:database"))

implementation(project(":core:collection"))
implementation(project(":core:navigation"))
implementation(project(":core:network"))
Expand Down
20 changes: 17 additions & 3 deletions build-logic/dependencies/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ 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)
}

tasks {
validatePlugins {
enableStricterValidation = true
failOnWarning = true
}
}

gradlePlugin {
Expand All @@ -28,5 +38,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
Expand Up @@ -3,11 +3,6 @@ import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType

object AppVersions {
const val VERSION_NAME = "1.71"
const val VERSION_CODE = 17
}

object AppExt {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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 {
"implementation"(currentLibs.findBundle("room").get())
"annotationProcessor"(currentLibs.findLibrary("androidx-room-compiler").get())
"implementation"(currentLibs.findLibrary("androidx-paging-runtime").get())
"androidTestApi"(currentLibs.findLibrary("androidx-room-testing").get())
"ksp"(currentLibs.findLibrary("androidx-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
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.library) apply false
alias(libs.plugins.serialization)
alias(libs.plugins.ksp) apply false
alias(libs.plugins.room) apply false
}

buildscript {
Expand Down
12 changes: 2 additions & 10 deletions core/database/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
plugins {
id("csplashscreen.android.library")
alias(libs.plugins.convention.library)
alias(libs.plugins.convention.room.library)
}

android.namespace = "st.slex.csplashscreen.core.database"

ksp {
arg("room.schemaLocation", "$projectDir/schemas")
}

dependencies {
implementation(project(":core:core"))
implementation(libs.bundles.room)
annotationProcessor(libs.androidx.room.compiler)
ksp(libs.androidx.room.compiler)
implementation(libs.androidx.paging.runtime)
androidTestApi(libs.androidx.room.testing)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import st.slex.csplashscreen.core.database.search.SearchEntity
)
abstract class AppDatabase : RoomDatabase() {

abstract val favouriteDao: FavouriteDao
abstract fun getFavouriteDao(): FavouriteDao

abstract val searchDao: SearchDao
abstract fun getSearchDao(): SearchDao

@RenameColumn(
tableName = "favourite_table",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ val moduleCoreDatabase = module {
.build()
}

single<SearchDao> { get<AppDatabase>().searchDao }
single<FavouriteDao> { get<AppDatabase>().favouriteDao }
single<SearchDao> { get<AppDatabase>().getSearchDao() }
single<FavouriteDao> { get<AppDatabase>().getFavouriteDao() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FavouriteDaoTest {
database = Room
.databaseBuilder(context, AppDatabase::class.java, AppDatabase.NAME)
.build()
dao = database.favouriteDao
dao = database.getFavouriteDao()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SearchDaoTest {
database = Room
.databaseBuilder(context, AppDatabase::class.java, AppDatabase.NAME)
.build()
dao = database.searchDao
dao = database.getSearchDao()
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("csplashscreen.android.library")
id("csplashscreen.android.library.compose")
alias(libs.plugins.convention.library)
alias(libs.plugins.convention.library.compose)
}

dependencies {
Expand Down
11 changes: 11 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 @@ -123,6 +127,13 @@ serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref
application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
room = { id = "androidx.room", version.ref = "room" }

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

[bundles]
lifecycle = [
Expand Down
Loading