Skip to content

Instantly share code, notes, and snippets.

@DaChelimo
Last active April 21, 2021 06:23
Show Gist options
  • Save DaChelimo/8cda77dd3b8a6204faf82624f4409553 to your computer and use it in GitHub Desktop.
Save DaChelimo/8cda77dd3b8a6204faf82624f4409553 to your computer and use it in GitHub Desktop.
Kotlin DSL Setup
plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-parcelize")
id("com.google.gms.google-services")
// id("dagger.hilt.android.plugin")
kotlin("kapt")
}
android {
compileSdkVersion(AppConfig.compileSdk)
buildToolsVersion(AppConfig.buildToolsVersion)
defaultConfig {
applicationId = "com.octagon_technologies.scafe"
minSdkVersion(AppConfig.minSdk)
targetSdkVersion(AppConfig.targetSdk)
versionCode = AppConfig.versionCode
versionName = AppConfig.versionName
testInstrumentationRunner = AppConfig.androidTestInstrumentation
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
useIR = true
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerVersion = "1.4.32"
kotlinCompilerExtensionVersion = "1.0.0-beta04"
}
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
// Core Kotlin and Android
implementation(AppDependencies.kotlinStdLib)
implementation(AppDependencies.coreAndroidKtx)
// implementation(AppDependencies.appCompat)
implementation(AppDependencies.coroutinesAndroid)
implementation(AppDependencies.coroutinesFirebase)
// Compose
implementation(AppDependencies.composeUi)
implementation(AppDependencies.composeFoundation)
implementation(AppDependencies.composeCompiler)
implementation(AppDependencies.composeMaterial)
implementation(AppDependencies.composeUITooling)
implementation(AppDependencies.composeActivity)
implementation(AppDependencies.composeConstraintLayout)
implementation(AppDependencies.composeGlide)
implementation(AppDependencies.composeSystemUI)
implementation(AppDependencies.composeNavigation)
// Libs
implementation(AppDependencies.material)
implementation(AppDependencies.liveData)
implementation(AppDependencies.timber)
implementation(AppDependencies.sdp)
implementation(AppDependencies.ssp)
implementation(AppDependencies.dataStore)
// Firebase
implementation(AppDependencies.firebaseAuth)
implementation(AppDependencies.firebaseDatabase)
implementation(AppDependencies.firebaseStorage)
// DI
// implementation(AppDependencies.hilt)
// implementation(AppDependencies.hiltViewModel)
// kapt(KaptDependencies.daggerHilt)
// kapt(KaptDependencies.googleHilt)
}
//app level config constants
object AppConfig {
const val compileSdk = 30
const val minSdk = 21
const val targetSdk = 30
const val versionCode = 1
const val versionName = "1.0.0"
const val buildToolsVersion = "29.0.3"
const val androidTestInstrumentation = "androidx.test.runner.AndroidJUnitRunner"
const val proguardConsumerRules = "consumer-rules.pro"
const val dimension = "environment"
}
object AppDependencies {
// Kotlin Standard Library
const val kotlinStdLib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}"
// Core
const val coreAndroidKtx = "androidx.core:core-ktx:${Versions.coreKtx}"
const val appCompat = "androidx.appcompat:appcompat:${Versions.appCompat}"
const val material = "com.google.android.material:material:${Versions.material}"
const val liveData = "androidx.lifecycle:lifecycle-livedata-ktx:${Versions.liveData}"
const val timber = "com.jakewharton.timber:timber:${Versions.timber}"
const val sdp = "com.intuit.sdp:sdp-android:${Versions.sdp}"
const val ssp = "com.intuit.ssp:ssp-android:${Versions.ssp}"
const val dataStore = "androidx.datastore:datastore-preferences:${Versions.datastore}"
// Coroutines
const val coroutinesAndroid =
"org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutines}"
const val coroutinesFirebase =
"org.jetbrains.kotlinx:kotlinx-coroutines-play-services:${Versions.coroutinesFirebase}"
// Network
const val moshi = "com.squareup.moshi:moshi:${Versions.moshi}"
const val retrofit = "com.squareup.retrofit2:retrofit:${Versions.retrofit}"
const val retrofitMoshiConverter =
"com.squareup.retrofit2:converter-moshi:${Versions.retrofitMoshiConverter}"
// Firebase
const val firebaseAuth = "com.google.firebase:firebase-auth-ktx:${Versions.firebaseAuth}"
const val firebaseStorage =
"com.google.firebase:firebase-storage-ktx:${Versions.firebaseStorage}"
const val firebaseDatabase =
"com.google.firebase:firebase-database-ktx:${Versions.firebaseDatabase}"
// DI
const val hilt = "com.google.dagger:hilt-android:${Versions.hilt}"
const val hiltViewModel = "androidx.hilt:hilt-lifecycle-viewmodel:${Versions.hiltViewModel}"
// Room
const val roomRuntime = "androidx.room:room-runtime:${Versions.room}"
const val roomKtx = "androidx.room:room-ktx:${Versions.room}"
// ViewModel
const val viewModelExtensions = "androidx.lifecycle:lifecycle-extensions:${Versions.viewModel}"
const val viewModelKtx = "androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.viewModel}"
// Compose
const val composeUi = "androidx.compose.ui:ui:${Versions.compose}"
const val composeCompiler = "androidx.compose.compiler:compiler:${Versions.compose}"
const val composeFoundation = "androidx.compose.foundation:foundation:${Versions.compose}"
const val composeMaterial = "androidx.compose.material:material:${Versions.compose}"
const val composeUITooling = "androidx.compose.ui:ui-tooling:${Versions.compose}"
const val composeNavigation = "androidx.navigation:navigation-compose:${Versions.composeNavigation}"
const val composeActivity = "androidx.activity:activity-compose:${Versions.composeActivity}"
const val composeGlide = "dev.chrisbanes.accompanist:accompanist-glide:${Versions.composeGlide}"
const val composeSystemUI = "com.google.accompanist:accompanist-systemuicontroller:${Versions.composeSystemUI}"
const val composeConstraintLayout = "androidx.constraintlayout:constraintlayout-compose:${Versions.composeConstraintLayout}"
// Test
const val junit = "junit:junit:${Versions.junit}"
// Android Testing
const val androidEspresso = "androidx.test.espresso:espresso-core:${Versions.androidEspresso}"
const val uiTestCompose = "androidx.compose.ui:ui-test-junit4:${Versions.compose}}"
const val androidJunit = "androidx.test.ext:junit:${Versions.androidJunit}"
// val appLibraries = arrayListOf<String>().apply {
// add(kotlinStdLib)
// add(coreKtx)
// add(appCompat)
// add(material)
//
// add(composeUi)
// add(composeMaterial)
// add(composeUITooling)
// add(composeNavigation)
// add(composeActivity)
// add(composeGlide)
// add(composeConstraintLayout)
//
// add(lifecycle)
// add(timber)
// add(roomRuntime)
// add(viewModelExtensions)
// add(viewModelKtx)
// add(retrofit)
// add(retrofitMoshiConverter)
// add(moshi)
// add(hilt)
// add(hiltViewModel)
// add(firebaseAuth)
// add(firebaseStorage)
// add(firebaseDatabase)
// }
//
// val kaptLibraries = arrayListOf<String>().apply {
// add(moshiCodegen)
// add(roomCompiler)
// add(googleHilt)
// add(daggerHilt)
// }
//
// val testLibraries = arrayListOf<String>().apply {
// add(junit)
// }
//
// val androidTestLibraries = arrayListOf<String>().apply {
// add(androidEspresso)
// add(uiTestCompose)
// add(androidJunit)
// }
}
//util functions for adding the different type dependencies from build.gradle file
//fun DependencyHandler.kapt(list: List<String>) {
// list.forEach { dependency ->
// add("kapt", dependency)
// }
//}
//fun DependencyHandler.implementation(list: List<String>) {
// list.forEach { dependency ->
// add("implementation", dependency)
// }
//}
//
//fun DependencyHandler.androidTestImplementation(list: List<String>) {
// list.forEach { dependency ->
// add("androidTestImplementation", dependency)
// }
//}
//
//fun DependencyHandler.testImplementation(list: List<String>) {
// list.forEach { dependency ->
// add("testImplementation", dependency)
// }
//}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.0.0-alpha14")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}")
classpath("com.google.gms:google-services:${Versions.gms}")
// classpath("com.google.dagger:hilt-android-gradle-plugin:${Versions.hilt}")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle.kts.kts files
}
}
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
import org.gradle.kotlin.dsl.`kotlin-dsl`
plugins {
`kotlin-dsl`
}
repositories {
jcenter()
}
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
fun DependencyHandler.implementation(projectDependency: ProjectDependency) {
add("implementation", projectDependency)
}
fun DependencyHandler.implementation(depName: String) {
add("implementation", depName)
}
fun DependencyHandler.kapt(depName: String) {
add("kapt", depName)
}
fun DependencyHandler.compileOnly(depName: String) {
add("compileOnly", depName)
}
fun DependencyHandler.api(depName: String) {
add("api", depName)
}
object Versions {
// App
const val gradle = "7.0.0-alpha12"
const val kotlin = "1.4.32"
const val gms = "4.3.5"
// Libs
const val coreKtx = "1.3.2"
const val appCompat = "1.2.0"
const val material = "1.3.0"
const val liveData = "2.3.1"
const val timber = "4.7.1"
const val coroutines = "1.4.3"
const val sdp = "1.0.6"
const val ssp = "1.0.6"
const val coroutinesFirebase = "1.4.1"
// Network
const val retrofit = "2.9.0"
const val moshi = "1.11.0"
const val retrofitMoshiConverter = "2.6.0"
// DI
const val hilt = "2.33-beta"
const val hiltViewModel = "1.0.0-alpha03"
const val hiltCompiler = "1.0.0-beta01"
// Firebase
const val firebaseAuth = "20.0.3"
const val firebaseStorage = "19.2.2"
const val firebaseDatabase = "19.7.0"
// Room
const val room = "2.2.6"
// Datastore
const val datastore = "1.0.0-alpha08"
// ViewModel
const val viewModel = "2.2.0"
// Compose
const val compose = "1.0.0-beta04"
const val composeActivity = "1.3.0-alpha05"
const val composeNavigation = "1.0.0-alpha10"
const val composeGlide = "0.6.2"
const val composeSystemUI = "0.7.1"
const val composeConstraintLayout = "1.0.0-alpha03"
// Test
const val junit = "4.13.2"
// Android Test
const val androidJunit = "1.1.2"
const val androidEspresso = "3.3.0"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment