Skip to content

Commit

Permalink
Better Gradle Dependency Management
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshayChordiya committed Mar 5, 2018
1 parent efbb0ce commit 0d48d59
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 30 deletions.
50 changes: 23 additions & 27 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

ext.android_support_version = '26.1.0'
ext.arch_version = '1.0.0'
ext.retrofit_version = '2.3.0'

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
compileSdkVersion Versions.compileSDK
buildToolsVersion Versions.buildTools
defaultConfig {
applicationId "com.akshay.newsapp"
minSdkVersion 15
versionCode 1
versionName "1.0"
minSdkVersion Versions.minSDK
versionCode Versions.versionCode
versionName Versions.versionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildConfigField("String", "NEWS_API_KEY", NEWS_API_KEY)
javaCompileOptions {
Expand All @@ -38,34 +34,34 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation Deps.kotlin

// Support Libraries
implementation "com.android.support:appcompat-v7:$android_support_version"
implementation "com.android.support:recyclerview-v7:$android_support_version"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation Deps.appCompat
implementation Deps.recyclerView
implementation Deps.constraintLayout

// Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation 'com.google.code.gson:gson:2.8.0'
implementation Deps.retrofit
implementation Deps.retrofitGsonConverter
implementation Deps.gson

// Architecture Components
implementation "android.arch.lifecycle:extensions:$arch_version"
implementation "android.arch.persistence.room:runtime:$arch_version"

kapt "android.arch.lifecycle:compiler:$arch_version"
kapt "android.arch.persistence.room:compiler:$arch_version"
implementation Deps.lifecycle
kapt Deps.lifecycleCompiler
implementation Deps.coreTesting
// Room
implementation Deps.room
kapt Deps.roomCompiler
implementation Deps.roomTesting

// Testing
testImplementation 'junit:junit:4.12'
debugImplementation 'com.amitshekhar.android:debug-db:1.0.1'
// Arch
testImplementation "android.arch.core:core-testing:$arch_version"
testImplementation Deps.junit
debugImplementation Deps.debugDb
// Retrofit
testImplementation "com.squareup.okhttp3:mockwebserver:3.8.1"
testImplementation Deps.mockWebServer
// UI
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
androidTestImplementation(Deps.espresso, {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.1.51'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath Deps.androidGradlePlugin
classpath Deps.kotlinGradlePlugin

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.iml
.gradle
/.idea
/build
gradle.properties
3 changes: 3 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
`kotlin-dsl`
}
72 changes: 72 additions & 0 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* A holder of all the versions.
*/
object Versions {

// Build Config
const val minSDK = 15
const val compileSDK = 26
const val targetSDK = 27
const val buildTools = "27.0.3"

// App version
const val versionCode = 2
const val versionName = "2.8.0"

// Plugins
const val androidGradlePlugin = "3.0.1"

// Dependencies
const val kotlin = "1.2.30"
const val support = "27.1.0"
const val constraintLayout = "1.0.2"
const val lifecycle = "1.1.0"
const val room = "1.0.0"
const val retrofit = "2.3.0"
const val gson = "2.8.2"
const val okHttp = "3.10.0"

// Testing
const val junit = "4.12"
const val espresso = "2.2.2"
const val debugDb = "1.0.1"
}

/**
* A holder of all the dependencies required by the app.
*/
object Deps {
// Kotlin
const val kotlin = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}"
const val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"

// Support Library
const val appCompat = "com.android.support:appcompat-v7:${Versions.support}"
const val recyclerView = "com.android.support:recyclerview-v7:${Versions.support}"
const val constraintLayout = "com.android.support.constraint:constraint-layout:${Versions.constraintLayout}"

// Architecture Components
const val lifecycle = "android.arch.lifecycle:extensions:${Versions.lifecycle}"
const val lifecycleCompiler = "android.arch.lifecycle:compiler:${Versions.lifecycle}"
const val coreTesting = "android.arch.core:core-testing:${Versions.lifecycle}"
// Room
const val room = "android.arch.persistence.room:runtime:${Versions.room}"
const val roomCompiler = "android.arch.persistence.room:compiler:${Versions.room}"
const val roomTesting = "android.arch.persistence.room:testing:${Versions.room}"

// Retrofit
const val retrofit = "com.squareup.retrofit2:retrofit:${Versions.retrofit}"
const val retrofitGsonConverter = "com.squareup.retrofit2:converter-gson:${Versions.retrofit}"
const val gson = "com.google.code.gson:gson:${Versions.gson}"
const val mockWebServer = "com.squareup.okhttp3:mockwebserver:${Versions.okHttp}"

// Testing
const val junit = "junit:junit:{${Versions.junit}"
const val espresso = "com.android.support.test.espresso:espresso-core:${Versions.espresso}"
const val debugDb = "com.amitshekhar.android:debug-db:${Versions.debugDb}"


// Android Gradle Plugin
const val androidGradlePlugin = "com.android.tools.build:gradle:${Versions.androidGradlePlugin}"

}

0 comments on commit 0d48d59

Please sign in to comment.