From 6bcb33e262e576ee070c90bd43dc6274b6d0d766 Mon Sep 17 00:00:00 2001 From: stslex Date: Tue, 21 May 2024 09:07:51 +0300 Subject: [PATCH 1/3] gradle refactor --- app/build.gradle.kts | 6 ++-- build-logic/dependencies/build.gradle.kts | 20 +++++++++-- .../AndroidApplicationConventionPlugin.kt | 5 +++ .../kotlin/AndroidLibraryConventionPlugin.kt | 5 +++ .../kotlin/RoomLibraryConventionPlugin.kt | 36 +++++++++++++++++++ .../st.slex.csplashscreen/KotlinAndroid.kt | 30 +++++----------- build.gradle.kts | 1 + core/database/build.gradle.kts | 12 ++----- .../core/database/AppDatabase.kt | 4 +-- .../core/database/di/ModuleCoreDatabase.kt | 4 +-- core/ui/build.gradle.kts | 4 +-- gradle/libs.versions.toml | 11 ++++++ 12 files changed, 94 insertions(+), 44 deletions(-) create mode 100644 build-logic/dependencies/src/main/kotlin/RoomLibraryConventionPlugin.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7168cb66..0a6cd1d4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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")) diff --git a/build-logic/dependencies/build.gradle.kts b/build-logic/dependencies/build.gradle.kts index 77c151af..c6882605 100644 --- a/build-logic/dependencies/build.gradle.kts +++ b/build-logic/dependencies/build.gradle.kts @@ -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 { @@ -28,5 +38,9 @@ gradlePlugin { id = "csplashscreen.android.library" implementationClass = "AndroidLibraryConventionPlugin" } + register("roomLibrary"){ + id = "csplashscreen.room.library" + implementationClass = "RoomLibraryConventionPlugin" + } } } \ No newline at end of file diff --git a/build-logic/dependencies/src/main/kotlin/AndroidApplicationConventionPlugin.kt b/build-logic/dependencies/src/main/kotlin/AndroidApplicationConventionPlugin.kt index af5a2ade..c5a8ad8b 100644 --- a/build-logic/dependencies/src/main/kotlin/AndroidApplicationConventionPlugin.kt +++ b/build-logic/dependencies/src/main/kotlin/AndroidApplicationConventionPlugin.kt @@ -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 @@ -35,6 +36,10 @@ class AndroidApplicationConventionPlugin : Plugin { configureSigning(target) } } + + extensions.configure { + arg("KOIN_CONFIG_CHECK", "true") + } } } } diff --git a/build-logic/dependencies/src/main/kotlin/AndroidLibraryConventionPlugin.kt b/build-logic/dependencies/src/main/kotlin/AndroidLibraryConventionPlugin.kt index 6a0d9370..d811cd82 100644 --- a/build-logic/dependencies/src/main/kotlin/AndroidLibraryConventionPlugin.kt +++ b/build-logic/dependencies/src/main/kotlin/AndroidLibraryConventionPlugin.kt @@ -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 @@ -36,6 +37,10 @@ class AndroidLibraryConventionPlugin : Plugin { } } + extensions.configure { + arg("KOIN_CONFIG_CHECK", "true") + } + val libs = extensions.getByType().named("libs") configurations.configureEach { resolutionStrategy { diff --git a/build-logic/dependencies/src/main/kotlin/RoomLibraryConventionPlugin.kt b/build-logic/dependencies/src/main/kotlin/RoomLibraryConventionPlugin.kt new file mode 100644 index 00000000..43f80bc0 --- /dev/null +++ b/build-logic/dependencies/src/main/kotlin/RoomLibraryConventionPlugin.kt @@ -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 { + + override fun apply(target: Project) { + with(target) { + pluginManager.apply("androidx.room") + pluginManager.apply("com.google.devtools.ksp") + + extensions.configure { + arg("room.generateKotlin", "true") + } + + extensions.configure { + // 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()) + } + } + } +} \ No newline at end of file diff --git a/build-logic/dependencies/src/main/kotlin/st.slex.csplashscreen/KotlinAndroid.kt b/build-logic/dependencies/src/main/kotlin/st.slex.csplashscreen/KotlinAndroid.kt index 927fbb27..c8d8f4df 100644 --- a/build-logic/dependencies/src/main/kotlin/st.slex.csplashscreen/KotlinAndroid.kt +++ b/build-logic/dependencies/src/main/kotlin/st.slex.csplashscreen/KotlinAndroid.kt @@ -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()) } } diff --git a/build.gradle.kts b/build.gradle.kts index b5f0d0b9..e09de459 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 { diff --git a/core/database/build.gradle.kts b/core/database/build.gradle.kts index 334a1587..613f1094 100644 --- a/core/database/build.gradle.kts +++ b/core/database/build.gradle.kts @@ -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) } \ No newline at end of file diff --git a/core/database/src/main/java/st/slex/csplashscreen/core/database/AppDatabase.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/AppDatabase.kt index 12342bc9..77541c6c 100644 --- a/core/database/src/main/java/st/slex/csplashscreen/core/database/AppDatabase.kt +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/AppDatabase.kt @@ -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", diff --git a/core/database/src/main/java/st/slex/csplashscreen/core/database/di/ModuleCoreDatabase.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/ModuleCoreDatabase.kt index 490f25a4..1cca16bf 100644 --- a/core/database/src/main/java/st/slex/csplashscreen/core/database/di/ModuleCoreDatabase.kt +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/ModuleCoreDatabase.kt @@ -17,6 +17,6 @@ val moduleCoreDatabase = module { .build() } - single { get().searchDao } - single { get().favouriteDao } + single { get().getSearchDao() } + single { get().getFavouriteDao() } } \ No newline at end of file diff --git a/core/ui/build.gradle.kts b/core/ui/build.gradle.kts index 97c47d6e..5c3a82f9 100644 --- a/core/ui/build.gradle.kts +++ b/core/ui/build.gradle.kts @@ -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 { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1904a94a..d7e83059 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,6 +2,7 @@ androidDesugarJdkLibs = "2.0.4" kotlin = "1.9.23" androidGradlePlugin = "8.3.2" +androidTools = "31.4.0" minSdk = "28" targetSdk = "34" @@ -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" } @@ -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 = [ From c578935fc3b39f1ba28334e67b160a38209516ee Mon Sep 17 00:00:00 2001 From: stslex Date: Tue, 21 May 2024 19:22:31 +0300 Subject: [PATCH 2/3] gradle refactor --- .../src/main/kotlin/{AppVersions.kt => AppExt.kt} | 5 ----- 1 file changed, 5 deletions(-) rename build-logic/dependencies/src/main/kotlin/{AppVersions.kt => AppExt.kt} (87%) diff --git a/build-logic/dependencies/src/main/kotlin/AppVersions.kt b/build-logic/dependencies/src/main/kotlin/AppExt.kt similarity index 87% rename from build-logic/dependencies/src/main/kotlin/AppVersions.kt rename to build-logic/dependencies/src/main/kotlin/AppExt.kt index a9bb6065..ff9c5119 100644 --- a/build-logic/dependencies/src/main/kotlin/AppVersions.kt +++ b/build-logic/dependencies/src/main/kotlin/AppExt.kt @@ -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 { /** From 90c6faeddf3988fc905d44b8a7505d7e6c238e0c Mon Sep 17 00:00:00 2001 From: stslex Date: Tue, 21 May 2024 20:28:18 +0300 Subject: [PATCH 3/3] fix ci --- .../st/slex/csplashscreen/core/database/FavouriteDaoTest.kt | 2 +- .../java/st/slex/csplashscreen/core/database/SearchDaoTest.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/database/src/test/java/st/slex/csplashscreen/core/database/FavouriteDaoTest.kt b/core/database/src/test/java/st/slex/csplashscreen/core/database/FavouriteDaoTest.kt index 5d2f897e..7d650d86 100644 --- a/core/database/src/test/java/st/slex/csplashscreen/core/database/FavouriteDaoTest.kt +++ b/core/database/src/test/java/st/slex/csplashscreen/core/database/FavouriteDaoTest.kt @@ -29,7 +29,7 @@ class FavouriteDaoTest { database = Room .databaseBuilder(context, AppDatabase::class.java, AppDatabase.NAME) .build() - dao = database.favouriteDao + dao = database.getFavouriteDao() } @Test diff --git a/core/database/src/test/java/st/slex/csplashscreen/core/database/SearchDaoTest.kt b/core/database/src/test/java/st/slex/csplashscreen/core/database/SearchDaoTest.kt index 49660458..3d999e78 100644 --- a/core/database/src/test/java/st/slex/csplashscreen/core/database/SearchDaoTest.kt +++ b/core/database/src/test/java/st/slex/csplashscreen/core/database/SearchDaoTest.kt @@ -27,7 +27,7 @@ class SearchDaoTest { database = Room .databaseBuilder(context, AppDatabase::class.java, AppDatabase.NAME) .build() - dao = database.searchDao + dao = database.getSearchDao() } @Test