From 96bde94dc7550719de4c9095fcf9aaf76e19ef42 Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Fri, 8 Nov 2024 00:31:29 +0600 Subject: [PATCH] feat[custom-plugin]: custom build-logic plugin implemented --- app/build.gradle.kts | 1 - base_unit_test/build.gradle.kts | 18 ++--------- build.gradle.kts | 2 +- buildSrc/build.gradle.kts | 10 +++---- .../src/main/kotlin/build-logic.gradle.kts | 30 ++++++++++++++++++- core/build.gradle.kts | 15 ++-------- data/build.gradle.kts | 20 ++----------- domain/build.gradle.kts | 20 ++----------- gradle/libs.versions.toml | 6 ++-- mock/build.gradle.kts | 16 +--------- presentation/build.gradle.kts | 19 ++---------- 11 files changed, 51 insertions(+), 106 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 118a52e..ffc3a3e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,4 +1,3 @@ -@Suppress("DSL_SCOPE_VIOLATION") plugins { id(libs.plugins.com.android.app.get().pluginId) id(libs.plugins.org.jetbrains.kotlin.android.get().pluginId) diff --git a/base_unit_test/build.gradle.kts b/base_unit_test/build.gradle.kts index cbc303e..ec97a6e 100644 --- a/base_unit_test/build.gradle.kts +++ b/base_unit_test/build.gradle.kts @@ -1,19 +1,11 @@ -@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed plugins { id(libs.plugins.com.android.library.get().pluginId) id(libs.plugins.org.jetbrains.kotlin.android.get().pluginId) + `build-logic` } android { namespace = "com.saiful.test.unit" - compileSdk = 34 - - defaultConfig { - minSdk = 24 - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - } buildTypes { release { @@ -24,13 +16,7 @@ android { ) } } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_19 - targetCompatibility = JavaVersion.VERSION_19 - } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_19.toString() - } + } dependencies { diff --git a/build.gradle.kts b/build.gradle.kts index eed8304..8a440a1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { id(libs.plugins.com.android.app.get().pluginId) apply false id(libs.plugins.com.android.library.get().pluginId) apply false id(libs.plugins.org.jetbrains.kotlin.android.get().pluginId) apply false - id(libs.plugins.hilt.plugin.get().pluginId) version "2.47" apply false + id(libs.plugins.hilt.plugin.get().pluginId) apply false id(libs.plugins.org.jetbrains.kotlin.kapt.get().pluginId) apply false id(libs.plugins.org.jetbrains.kotlin.jvm.get().pluginId) apply false id(libs.plugins.gms.google.service.get().pluginId) version "4.4.1" apply false diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 6143e16..3c2fa0f 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,10 +1,10 @@ plugins { `kotlin-dsl` + `kotlin-dsl-precompiled-script-plugins` } dependencies { - implementation(gradleApi()) - implementation(libs.build.gradle) - implementation(libs.build.gradle.api) - implementation(libs.kotlin.gradle) -} \ No newline at end of file + implementation(libs.android.gradlePlugin) + implementation(libs.kotlin.gradlePlugin) + implementation(libs.hilt.plugin) +} diff --git a/buildSrc/src/main/kotlin/build-logic.gradle.kts b/buildSrc/src/main/kotlin/build-logic.gradle.kts index 00cb2e6..3cf8139 100644 --- a/buildSrc/src/main/kotlin/build-logic.gradle.kts +++ b/buildSrc/src/main/kotlin/build-logic.gradle.kts @@ -1,3 +1,31 @@ plugins { - + id("com.android.library") + id("org.jetbrains.kotlin.android") } + +internal val Project.libs: VersionCatalog get() = + project.extensions.getByType().named("libs") + +android { + compileSdk = 34 + + defaultConfig { + minSdk = 24 + targetSdk = 33 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + vectorDrawables { + useSupportLibrary = true + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_19 + targetCompatibility = JavaVersion.VERSION_19 + } + kotlinOptions { + jvmTarget = JavaVersion.VERSION_19.toString() + } + +} \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 3231570..a23adfd 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,19 +1,14 @@ -@Suppress("DSL_SCOPE_VIOLATION") plugins { id(libs.plugins.com.android.library.get().pluginId) id(libs.plugins.org.jetbrains.kotlin.android.get().pluginId) id(libs.plugins.org.jetbrains.kotlin.kapt.get().pluginId) + `build-logic` } android { namespace = "com.saiful.core" - compileSdk = 34 defaultConfig { - minSdk = 24 - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") val clientID: String by project val apiKey = System.getenv("CLIENT_ID") ?: clientID @@ -32,13 +27,7 @@ android { ) } } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_19 - targetCompatibility = JavaVersion.VERSION_19 - } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_19.toString() - } + buildFeatures { buildConfig = true } diff --git a/data/build.gradle.kts b/data/build.gradle.kts index 1a2c817..e88d3a4 100644 --- a/data/build.gradle.kts +++ b/data/build.gradle.kts @@ -1,21 +1,13 @@ -@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed plugins { id(libs.plugins.com.android.library.get().pluginId) id(libs.plugins.org.jetbrains.kotlin.android.get().pluginId) - alias(libs.plugins.hilt.plugin) + id(libs.plugins.hilt.plugin.get().pluginId) id(libs.plugins.org.jetbrains.kotlin.kapt.get().pluginId) + `build-logic` } android { namespace = "com.saiful.data" - compileSdk = 34 - - defaultConfig { - minSdk = 24 - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - } buildTypes { release { @@ -26,13 +18,7 @@ android { ) } } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_19 - targetCompatibility = JavaVersion.VERSION_19 - } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_19.toString() - } + testOptions { unitTests.isReturnDefaultValues = true } diff --git a/domain/build.gradle.kts b/domain/build.gradle.kts index 673b832..d7584ed 100644 --- a/domain/build.gradle.kts +++ b/domain/build.gradle.kts @@ -1,21 +1,13 @@ -@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed plugins { id(libs.plugins.com.android.library.get().pluginId) id(libs.plugins.org.jetbrains.kotlin.android.get().pluginId) - alias(libs.plugins.hilt.plugin) + id(libs.plugins.hilt.plugin.get().pluginId) id(libs.plugins.org.jetbrains.kotlin.kapt.get().pluginId) + `build-logic` } android { namespace = "com.saiful.domain" - compileSdk = 34 - - defaultConfig { - minSdk = 24 - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - } buildTypes { release { @@ -26,13 +18,7 @@ android { ) } } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_19 - targetCompatibility = JavaVersion.VERSION_19 - } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_19.toString() - } + testOptions { unitTests.isReturnDefaultValues = true } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 82ae10c..7891edf 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -79,9 +79,9 @@ firebase-crashlytics = { group = "com.google.firebase", name = "firebase-crashly mock-webserver = { group = "com.squareup.okhttp3", name = "mockwebserver", version.ref = "mock-webserver" } logging-interceptor = {group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "logging-interceptor"} -build-gradle = {group = "com.android.tools.build", name ="gradle", version.ref = "agp"} -build-gradle-api = {group = "com.android.tools.build", name = "gradle-api", version.ref = "agp"} -kotlin-gradle = {group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin-bom"} +# Dependencies of the included build-logic +android-gradlePlugin = {group = "com.android.tools.build", name ="gradle", version.ref = "agp"} +kotlin-gradlePlugin = {group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin-bom"} #Test junit = { group = "junit", name = "junit", version.ref = "junit" } diff --git a/mock/build.gradle.kts b/mock/build.gradle.kts index 1f9c39c..6e435b0 100644 --- a/mock/build.gradle.kts +++ b/mock/build.gradle.kts @@ -2,18 +2,11 @@ plugins { id(libs.plugins.com.android.library.get().pluginId) id(libs.plugins.org.jetbrains.kotlin.android.get().pluginId) id(libs.plugins.org.jetbrains.kotlin.kapt.get().pluginId) + `build-logic` } android { namespace = "com.saiful.mock" - compileSdk = 34 - - defaultConfig { - minSdk = 24 - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - } buildTypes { release { @@ -24,13 +17,6 @@ android { ) } } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = "1.8" - } } dependencies { diff --git a/presentation/build.gradle.kts b/presentation/build.gradle.kts index 367dd3a..3a4929c 100644 --- a/presentation/build.gradle.kts +++ b/presentation/build.gradle.kts @@ -1,21 +1,13 @@ -@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed plugins { id(libs.plugins.com.android.library.get().pluginId) id(libs.plugins.org.jetbrains.kotlin.android.get().pluginId) - alias(libs.plugins.hilt.plugin) + id(libs.plugins.hilt.plugin.get().pluginId) id(libs.plugins.org.jetbrains.kotlin.kapt.get().pluginId) + `build-logic` } android { namespace = "com.saiful.presentation" - compileSdk = 34 - - defaultConfig { - minSdk = 24 - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - } buildTypes { release { @@ -27,13 +19,6 @@ android { } } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_19 - targetCompatibility = JavaVersion.VERSION_19 - } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_19.toString() - } buildFeatures { compose = true }