Skip to content

Commit 0d48d59

Browse files
Better Gradle Dependency Management
1 parent efbb0ce commit 0d48d59

5 files changed

Lines changed: 105 additions & 30 deletions

File tree

app/build.gradle

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44
apply plugin: 'kotlin-kapt'
55

6-
ext.android_support_version = '26.1.0'
7-
ext.arch_version = '1.0.0'
8-
ext.retrofit_version = '2.3.0'
9-
106
android {
11-
compileSdkVersion 26
12-
buildToolsVersion '26.0.2'
7+
compileSdkVersion Versions.compileSDK
8+
buildToolsVersion Versions.buildTools
139
defaultConfig {
1410
applicationId "com.akshay.newsapp"
15-
minSdkVersion 15
16-
versionCode 1
17-
versionName "1.0"
11+
minSdkVersion Versions.minSDK
12+
versionCode Versions.versionCode
13+
versionName Versions.versionName
1814
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1915
buildConfigField("String", "NEWS_API_KEY", NEWS_API_KEY)
2016
javaCompileOptions {
@@ -38,34 +34,34 @@ dependencies {
3834
implementation fileTree(dir: 'libs', include: ['*.jar'])
3935

4036
// Kotlin
41-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
37+
implementation Deps.kotlin
4238

4339
// Support Libraries
44-
implementation "com.android.support:appcompat-v7:$android_support_version"
45-
implementation "com.android.support:recyclerview-v7:$android_support_version"
46-
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
40+
implementation Deps.appCompat
41+
implementation Deps.recyclerView
42+
implementation Deps.constraintLayout
4743

4844
// Retrofit
49-
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
50-
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
51-
implementation 'com.google.code.gson:gson:2.8.0'
45+
implementation Deps.retrofit
46+
implementation Deps.retrofitGsonConverter
47+
implementation Deps.gson
5248

5349
// Architecture Components
54-
implementation "android.arch.lifecycle:extensions:$arch_version"
55-
implementation "android.arch.persistence.room:runtime:$arch_version"
56-
57-
kapt "android.arch.lifecycle:compiler:$arch_version"
58-
kapt "android.arch.persistence.room:compiler:$arch_version"
50+
implementation Deps.lifecycle
51+
kapt Deps.lifecycleCompiler
52+
implementation Deps.coreTesting
53+
// Room
54+
implementation Deps.room
55+
kapt Deps.roomCompiler
56+
implementation Deps.roomTesting
5957

6058
// Testing
61-
testImplementation 'junit:junit:4.12'
62-
debugImplementation 'com.amitshekhar.android:debug-db:1.0.1'
63-
// Arch
64-
testImplementation "android.arch.core:core-testing:$arch_version"
59+
testImplementation Deps.junit
60+
debugImplementation Deps.debugDb
6561
// Retrofit
66-
testImplementation "com.squareup.okhttp3:mockwebserver:3.8.1"
62+
testImplementation Deps.mockWebServer
6763
// UI
68-
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
64+
androidTestImplementation(Deps.espresso, {
6965
exclude group: 'com.android.support', module: 'support-annotations'
7066
})
7167
}

build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.1.51'
54
repositories {
65
google()
76
jcenter()
87
}
98
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.0.0'
11-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
9+
classpath Deps.androidGradlePlugin
10+
classpath Deps.kotlinGradlePlugin
1211

1312
// NOTE: Do not place your application dependencies here; they belong
1413
// in the individual module build.gradle files

buildSrc/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.iml
2+
.gradle
3+
/.idea
4+
/build
5+
gradle.properties

buildSrc/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* A holder of all the versions.
3+
*/
4+
object Versions {
5+
6+
// Build Config
7+
const val minSDK = 15
8+
const val compileSDK = 26
9+
const val targetSDK = 27
10+
const val buildTools = "27.0.3"
11+
12+
// App version
13+
const val versionCode = 2
14+
const val versionName = "2.8.0"
15+
16+
// Plugins
17+
const val androidGradlePlugin = "3.0.1"
18+
19+
// Dependencies
20+
const val kotlin = "1.2.30"
21+
const val support = "27.1.0"
22+
const val constraintLayout = "1.0.2"
23+
const val lifecycle = "1.1.0"
24+
const val room = "1.0.0"
25+
const val retrofit = "2.3.0"
26+
const val gson = "2.8.2"
27+
const val okHttp = "3.10.0"
28+
29+
// Testing
30+
const val junit = "4.12"
31+
const val espresso = "2.2.2"
32+
const val debugDb = "1.0.1"
33+
}
34+
35+
/**
36+
* A holder of all the dependencies required by the app.
37+
*/
38+
object Deps {
39+
// Kotlin
40+
const val kotlin = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}"
41+
const val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
42+
43+
// Support Library
44+
const val appCompat = "com.android.support:appcompat-v7:${Versions.support}"
45+
const val recyclerView = "com.android.support:recyclerview-v7:${Versions.support}"
46+
const val constraintLayout = "com.android.support.constraint:constraint-layout:${Versions.constraintLayout}"
47+
48+
// Architecture Components
49+
const val lifecycle = "android.arch.lifecycle:extensions:${Versions.lifecycle}"
50+
const val lifecycleCompiler = "android.arch.lifecycle:compiler:${Versions.lifecycle}"
51+
const val coreTesting = "android.arch.core:core-testing:${Versions.lifecycle}"
52+
// Room
53+
const val room = "android.arch.persistence.room:runtime:${Versions.room}"
54+
const val roomCompiler = "android.arch.persistence.room:compiler:${Versions.room}"
55+
const val roomTesting = "android.arch.persistence.room:testing:${Versions.room}"
56+
57+
// Retrofit
58+
const val retrofit = "com.squareup.retrofit2:retrofit:${Versions.retrofit}"
59+
const val retrofitGsonConverter = "com.squareup.retrofit2:converter-gson:${Versions.retrofit}"
60+
const val gson = "com.google.code.gson:gson:${Versions.gson}"
61+
const val mockWebServer = "com.squareup.okhttp3:mockwebserver:${Versions.okHttp}"
62+
63+
// Testing
64+
const val junit = "junit:junit:{${Versions.junit}"
65+
const val espresso = "com.android.support.test.espresso:espresso-core:${Versions.espresso}"
66+
const val debugDb = "com.amitshekhar.android:debug-db:${Versions.debugDb}"
67+
68+
69+
// Android Gradle Plugin
70+
const val androidGradlePlugin = "com.android.tools.build:gradle:${Versions.androidGradlePlugin}"
71+
72+
}

0 commit comments

Comments
 (0)