Skip to content

Instantly share code, notes, and snippets.

@AniketSK
Created November 14, 2018 18:58
Show Gist options
  • Save AniketSK/071b07503337093ffdcd5d1135209e41 to your computer and use it in GitHub Desktop.
Save AniketSK/071b07503337093ffdcd5d1135209e41 to your computer and use it in GitHub Desktop.
Demonstration of how to extract dependencies from your build.gradle file.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
// Load dependencies
buildscript {
ext.kotlin_version = "1.3.0"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply from: 'gradleScripts/dependencies.gradle'
ext {
//Version
supportLibrary = '28.0.0'
rxjava = "2.2.2"
rxandroid = "2.1.0"
dagger = "2.17"
mockwebserver = "3.11.0"
gson = "2.8.5"
mockito = "2.22.0"
firestore = "17.1.0"
firebaseui = "4.1.0"
retrofit = "2.4.0"
constraintlayout = "1.1.3"
archextensions = "1.1.1"
constraintlayout = [
//api
lib : "com.android.support.constraint:constraint-layout:$constraintlayout"
]
archextensions = [
lib: "android.arch.lifecycle:extensions:$archextensions"
]
//Support Libraries dependencies
supportDependencies = [
design : "com.android.support:design:${supportLibrary}",
recyclerView : "com.android.support:recyclerview-v7:${supportLibrary}",
cardView : "com.android.support:cardview-v7:${supportLibrary}",
appCompat : "com.android.support:appcompat-v7:${supportLibrary}",
supportAnnotation: "com.android.support:support-annotations:${supportLibrary}",
]
rxjava = [
lib : "io.reactivex.rxjava2:rxjava:${rxjava}",
android: "io.reactivex.rxjava2:rxandroid:${rxandroid}"
]
dagger = [
// Dagger
lib : "com.google.dagger:dagger:${dagger}",
kapt : "com.google.dagger:dagger-compiler:${dagger}",
android : "com.google.dagger:dagger-android:${dagger}",
support : "com.google.dagger:dagger-android-support:${dagger}",
annotationProcessor: "com.google.dagger:dagger-android-processor:${dagger}",
]
mockwebserver = [
lib: "com.squareup.okhttp3:mockwebserver:$mockwebserver"
]
gson = [
lib: "com.google.code.gson:gson:$gson"
]
mockito = [
lib : "org.mockito:mockito-core:$mockito",
android: "org.mockito:mockito-android:$mockito"
]
}
@AniketSK
Copy link
Author

Create a seprate file, for instance, a dependencies.gradle under the folder gradleScripts in the root of your project.
Then, in the project level build.gradle:
apply from: 'gradleScripts/dependencies.gradle'
That's it! Now you can share common declarations for versions name names of dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment