Last active
July 27, 2024 08:47
-
-
Save f3401pal/8aa468192a4d35642e20abf9dbd8de4c to your computer and use it in GitHub Desktop.
Multi-module Android project with Kotlin DSL for Gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
`android-base-app` | |
`android-base` | |
id("io.fabric") | |
} | |
android { | |
defaultConfig { | |
versionCode = 20 | |
versionName = "1.6.3" | |
} | |
buildTypes { | |
getByName("debug") { | |
isMinifyEnabled = false | |
} | |
getByName("release") { | |
isMinifyEnabled = true | |
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") | |
} | |
} | |
} | |
dependencies { | |
implementation(project(":data")) | |
implementation(project(":domain")) | |
appCompat() | |
lifecycle() | |
implementation(Dependencies.ANDROID_MATERIAL) | |
implementation(Dependencies.ANDROID_BROWSER) | |
implementation(Dependencies.ANDROID_WORK_MANAGER) | |
implementation(Dependencies.GMS_MAP) | |
implementation(Dependencies.CRASHLYTICS) | |
firebase() | |
// Dagger Android dependencies | |
dagger() | |
} | |
apply(plugin = "com.google.gms.google-services") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id("com.android.library") | |
kotlin("android") | |
} | |
android { | |
compileSdkVersion(Versions.TARGET_ANDROID_SDK) | |
defaultConfig { | |
minSdkVersion(Versions.MIN_ANDROID_SDK) | |
targetSdkVersion(Versions.TARGET_ANDROID_SDK) | |
versionCode = 1 | |
versionName = "1.0" | |
consumerProguardFiles("consumer-rules.pro") | |
} | |
compileOptions { | |
sourceCompatibility = JavaVersion.VERSION_1_8 | |
targetCompatibility = JavaVersion.VERSION_1_8 | |
} | |
kotlinOptions { | |
val options = this as KotlinJvmOptions | |
options.jvmTarget = "1.8" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
kotlin("android.extensions") | |
kotlin("kapt") | |
} | |
dependencies { | |
implementation(Dependencies.TIMBER) | |
implementation(Dependencies.COROUTINES_ANDROID) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
`kotlin-dsl` | |
} | |
repositories { | |
jcenter() | |
google() | |
} | |
dependencies { | |
// android gradle plugin, required by custom plugin | |
implementation("com.android.tools.build:gradle:3.5.3") | |
// kotlin plugin, required by custom plugin | |
implementation(kotlin("gradle-plugin", "1.3.61")) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.f3401pal.cbe | |
import org.gradle.api.artifacts.dsl.DependencyHandler | |
object Dependencies { | |
const val ANDROID_APP_COMPAT = "androidx.appcompat:appcompat:${Versions.Androidx.APP_COMPAT}" | |
const val ANDROID_CORE_KTX = "androidx.core:core-ktx:${Versions.Androidx.CORE_KTX}" | |
const val ANDROID_WORK_MANAGER = "androidx.work:work-runtime-ktx:${Versions.Androidx.WORK_MANAGER}" | |
const val ANDROID_BROWSER = "androidx.browser:browser:${Versions.Androidx.BROWSER}" | |
const val ANDROID_MATERIAL = "com.google.android.material:material:${Versions.MATERIAL_ANDROID}" | |
const val GMS_MAP = "com.google.android.gms:play-services-maps:${Versions.GMS_MAP}" | |
const val CRASHLYTICS = "com.crashlytics.sdk.android:crashlytics:${Versions.CRASHLYTICS}" | |
const val ANDROID_ROOM_RUNTIME = "androidx.room:room-runtime:${Versions.Androidx.ROOM}" | |
const val ANDROID_ROOM_KTX = "androidx.room:room-ktx:${Versions.Androidx.ROOM}" | |
const val ANDROID_ROOM_COMPILER = "androidx.room:room-compiler:${Versions.Androidx.ROOM}" | |
const val ANDROID_LIFECYCLE_RUNTIME = "androidx.lifecycle:lifecycle-runtime:${Versions.Androidx.LIFECYCLE}" | |
const val ANDROID_LIFECYCLE_VIEWMODEL = "androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.Androidx.LIFECYCLE}" | |
const val ANDROID_LIFECYCLE_EX = "androidx.lifecycle:lifecycle-extensions:${Versions.Androidx.LIFECYCLE}" | |
const val ANDROID_LIFECYCLE_LIVEDATA = "androidx.lifecycle:lifecycle-livedata-ktx:${Versions.Androidx.LIFECYCLE}" | |
const val JSOUP = "org.jsoup:jsoup:${Versions.JSOUP}" | |
const val TIMBER = "com.jakewharton.timber:timber:${Versions.TIMBER}" | |
const val RETROFIT = "com.squareup.retrofit2:retrofit:${Versions.RETROFIT}" | |
const val RETROFIT_CONVERTER_MOSHI = "com.squareup.retrofit2:converter-moshi:${Versions.RETROFIT}" | |
const val MOSHI = "com.squareup.moshi:moshi-kotlin:${Versions.MOSHI}" | |
const val MOSHI_CODEGEN = "com.squareup.moshi:moshi-kotlin-codegen:${Versions.MOSHI}" | |
const val COROUTINES_ANDROID = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.COROUTINES_ANDROID}" | |
const val OKHTTP_LOGGER = "com.squareup.okhttp3:logging-interceptor:${Versions.OKHTTP3}" | |
const val DAGGER = "com.google.dagger:dagger:${Versions.DAGGER2}" | |
const val DAGGER_COMPILER = "com.google.dagger:dagger-compiler:${Versions.DAGGER2}" | |
const val DAGGER_ANDROID = "com.google.dagger:dagger-android-support:${Versions.DAGGER2}" | |
const val DAGGER_ANDROID_PROCESSOR = "com.google.dagger:dagger-android-processor:${Versions.DAGGER2}" | |
const val FIREBASE_CORE = "com.google.firebase:firebase-core:${Versions.Firebase.CORE}" | |
const val FIREBASE_ADS = "com.google.firebase:firebase-ads:${Versions.Firebase.ADS}" | |
const val FIREBASE_APP_INDEXING = "com.google.firebase:firebase-appindexing:${Versions.Firebase.APP_INDEX}" | |
} | |
fun DependencyHandler.firebase() { | |
implementation(Dependencies.FIREBASE_CORE) | |
implementation(Dependencies.FIREBASE_ADS) | |
implementation(Dependencies.FIREBASE_APP_INDEXING) | |
} | |
fun DependencyHandler.dagger() { | |
compileOnly(Dependencies.DAGGER) | |
kapt(Dependencies.DAGGER_COMPILER) | |
implementation(Dependencies.DAGGER_ANDROID) | |
kapt(Dependencies.DAGGER_ANDROID_PROCESSOR) | |
} | |
fun DependencyHandler.appCompat() { | |
implementation(Dependencies.ANDROID_APP_COMPAT) | |
implementation(Dependencies.ANDROID_CORE_KTX) | |
} | |
fun DependencyHandler.lifecycle() { | |
implementation(Dependencies.ANDROID_LIFECYCLE_RUNTIME) | |
implementation(Dependencies.ANDROID_LIFECYCLE_EX) | |
implementation(Dependencies.ANDROID_LIFECYCLE_VIEWMODEL) | |
implementation(Dependencies.ANDROID_LIFECYCLE_LIVEDATA) | |
} | |
fun DependencyHandler.retrofit() { | |
implementation(Dependencies.RETROFIT) | |
implementation(Dependencies.RETROFIT_CONVERTER_MOSHI) | |
implementation(Dependencies.OKHTTP_LOGGER) | |
} | |
fun DependencyHandler.moshi() { | |
implementation(Dependencies.MOSHI) | |
kapt(Dependencies.MOSHI_CODEGEN) | |
} | |
fun DependencyHandler.room() { | |
api(Dependencies.ANDROID_ROOM_RUNTIME) | |
implementation(Dependencies.ANDROID_ROOM_KTX) | |
kapt(Dependencies.ANDROID_ROOM_COMPILER) | |
} | |
fun DependencyHandler.implementation(depName: String) { | |
add("implementation", depName) | |
} | |
private fun DependencyHandler.kapt(depName: String) { | |
add("kapt", depName) | |
} | |
private fun DependencyHandler.compileOnly(depName: String) { | |
add("compileOnly", depName) | |
} | |
private fun DependencyHandler.api(depName: String) { | |
add("api", depName) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.f3401pal.cbe | |
object Versions { | |
const val MIN_ANDROID_SDK = 21 | |
const val TARGET_ANDROID_SDK = 29 | |
object Androidx { | |
const val APP_COMPAT = "1.1.0" | |
const val LIFECYCLE = "2.2.0" | |
const val CORE_KTX = "1.1.0" | |
const val WORK_MANAGER = "2.3.0" | |
const val BROWSER = "1.2.0" | |
const val ROOM = "2.2.3" | |
} | |
object Firebase { | |
const val CORE = "17.2.2" | |
const val ADS = "18.3.0" | |
const val APP_INDEX = "19.1.0" | |
} | |
const val CRASHLYTICS = "2.10.1" | |
const val GMS_MAP = "17.0.0" | |
const val MATERIAL_ANDROID = "1.2.0-alpha04" | |
const val COROUTINES_ANDROID = "1.3.3" | |
const val DAGGER2 = "2.26" | |
const val JSOUP = "1.12.1" | |
const val TIMBER = "4.7.1" | |
const val RETROFIT = "2.7.1" | |
const val MOSHI = "1.9.2" | |
const val OKHTTP3 = "4.3.1" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
`android-base-lib` | |
`android-base` | |
} | |
dependencies { | |
appCompat() | |
// Room | |
room() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
`android-base-lib` | |
`android-base` | |
} | |
dependencies { | |
implementation(project(":data")) | |
appCompat() | |
implementation(Dependencies.ANDROID_WORK_MANAGER) | |
implementation(Dependencies.JSOUP) | |
// Network | |
retrofit() | |
// JSON parser | |
moshi() | |
} |
I'm getting an error when trying to create the buildSrc\android-base.gradle.kts
Caused by: java.lang.Exception: The plugins {} block must not be used here. If you need to apply a plugin imperatively, please use apply<PluginType>() or apply(plugin = "id") instead. at org.gradle.kotlin.dsl.support.CompiledKotlinBuildScriptKt.invalidPluginsCall(CompiledKotlinBuildScript.kt:143) at org.gradle.kotlin.dsl.support.CompiledKotlinBuildScript.plugins(CompiledKotlinBuildScript.kt:61) at Android_base_gradle.<init>(Unknown Source) ... 121 more ], scriptFile = ...\buildSrc\android-base.gradle.kts)
i'm using AS 4.0, Gradle plugin 4.0.0 with koltin 1.3.71
look here diffplug/spotless#740 (comment)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting an error when trying to create the buildSrc\android-base.gradle.kts
Caused by: java.lang.Exception: The plugins {} block must not be used here. If you need to apply a plugin imperatively, please use apply<PluginType>() or apply(plugin = "id") instead. at org.gradle.kotlin.dsl.support.CompiledKotlinBuildScriptKt.invalidPluginsCall(CompiledKotlinBuildScript.kt:143) at org.gradle.kotlin.dsl.support.CompiledKotlinBuildScript.plugins(CompiledKotlinBuildScript.kt:61) at Android_base_gradle.<init>(Unknown Source) ... 121 more ], scriptFile = ...\buildSrc\android-base.gradle.kts)
i'm using AS 4.0, Gradle plugin 4.0.0 with koltin 1.3.71