Skip to content

Commit

Permalink
Use Kotlin DSL for Gradle files
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniolg committed Nov 5, 2017
1 parent 0846ee6 commit 470feb7
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 144 deletions.
84 changes: 0 additions & 84 deletions app/build.gradle

This file was deleted.

83 changes: 83 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.kotlin
import org.gradle.kotlin.dsl.setValue

/*
* Copyright (C) 2015 Antonio Leiva
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id("com.android.application")
kotlin("android")
kotlin("kapt")
}

val config = ProjectConfiguration()

android {
compileSdkVersion(config.android.compileSdkVersion)
buildToolsVersion(config.android.buildToolsVersion)

defaultConfig {
applicationId = config.android.applicationId
minSdkVersion(config.android.minSdkVersion)
targetSdkVersion(config.android.targetSdkVersion)
versionCode = config.android.versionCode
versionName = config.android.versionName

testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles("proguard-rules.pro")
}
}
}

dependencies {
compile(config.libs.kotlin_std)
compile(config.libs.appcompat)
compile(config.libs.recyclerview)
compile(config.libs.cardview)
compile(config.libs.palette)
compile(config.libs.design)
compile(config.libs.eventbus)
compile(config.libs.picasso)
compile(config.libs.okhttp)
compile(config.libs.okhttp_interceptor)
compile(config.libs.retrofit)
compile(config.libs.retrofit_gson)
compile(config.libs.jobqueue)
compile(config.libs.anko_sdk15)
compile(config.libs.anko_support)
compile(config.libs.anko_appcompat)
compile(config.libs.anko_design)
compile(config.libs.anko_cardview)
compile(config.libs.anko_recyclerview)
kapt(config.libs.dagger_compiler)
compile(config.libs.dagger)

testCompile(config.testLibs.junit)
testCompile(config.testLibs.mockito)

androidTestCompile(config.testLibs.mockito)
androidTestCompile(config.testLibs.dexmaker)
androidTestCompile(config.testLibs.dexmaker_mockito)
androidTestCompile(config.testLibs.annotations)
androidTestCompile(config.testLibs.espresso)
}
59 changes: 0 additions & 59 deletions build.gradle

This file was deleted.

41 changes: 41 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.setValue
import org.gradle.kotlin.dsl.repositories

/*
* Copyright (C) 2015 Antonio Leiva
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

buildscript {

val config = ProjectConfiguration()

repositories {
jcenter()
google()
}
dependencies {
classpath(config.buildPlugins.androidGradle)
classpath(config.buildPlugins.kotlinGradlePlugin)
}
}

allprojects {
repositories {
jcenter()
google()
}
}
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`
}
71 changes: 71 additions & 0 deletions buildSrc/src/main/kotlin/ProjectConfiguration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
val kotlinVersion = "1.1.51"
val androidGradleVersion = "3.0.0"

// Compile dependencies
val supportVersion = "26.1.0"
val ankoVersion = "0.10.2"
val daggerVersion = "2.11"
val retrofitVersion = "2.3.0"
val okhttpVersion = "3.9.0"
val eventBusVersion = "2.4.1"
val picassoVersion = "2.5.2"
val priorityJobQueueVersion = "2.0.1"

// Unit tests
val mockitoVersion = "2.8.47"

class ProjectConfiguration {
val buildPlugins = BuildPlugins()
val android = Android()
val libs = Libs()
val testLibs = TestLibs()
}

class BuildPlugins {
val androidGradle = "com.android.tools.build:gradle:$androidGradleVersion"
val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}

class Android {
val buildToolsVersion = "26.0.2"
val minSdkVersion = 19
val targetSdkVersion = 26
val compileSdkVersion = 26
val applicationId = "com.antonioleiva.bandhookkotlin"
val versionCode = 1
val versionName = "0.1"

}

class Libs {
val kotlin_std = "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
val appcompat = "com.android.support:appcompat-v7:$supportVersion"
val recyclerview = "com.android.support:recyclerview-v7:$supportVersion"
val cardview = "com.android.support:cardview-v7:$supportVersion"
val palette = "com.android.support:palette-v7:$supportVersion"
val design = "com.android.support:design:$supportVersion"
val eventbus = "de.greenrobot:eventbus:$eventBusVersion"
val picasso = "com.squareup.picasso:picasso:$picassoVersion"
val okhttp = "com.squareup.okhttp3:okhttp:$okhttpVersion"
val okhttp_interceptor = "com.squareup.okhttp3:logging-interceptor:$okhttpVersion"
val retrofit = "com.squareup.retrofit2:retrofit:$retrofitVersion"
val retrofit_gson = "com.squareup.retrofit2:converter-gson:$retrofitVersion"
val jobqueue = "com.birbit:android-priority-jobqueue:$priorityJobQueueVersion"
val anko_sdk15 = "org.jetbrains.anko:anko-sdk15:$ankoVersion"
val anko_support = "org.jetbrains.anko:anko-support-v4:$ankoVersion"
val anko_appcompat = "org.jetbrains.anko:anko-appcompat-v7:$ankoVersion"
val anko_design = "org.jetbrains.anko:anko-design:$ankoVersion"
val anko_cardview = "org.jetbrains.anko:anko-cardview-v7:$ankoVersion"
val anko_recyclerview = "org.jetbrains.anko:anko-recyclerview-v7:$ankoVersion"
val dagger_compiler = "com.google.dagger:dagger-compiler:$daggerVersion"
val dagger = "com.google.dagger:dagger:$daggerVersion"
}

class TestLibs {
val junit = "junit:junit:4.12"
val mockito = "org.mockito:mockito-core:$mockitoVersion"
val dexmaker = "com.google.dexmaker:dexmaker:1.2"
val dexmaker_mockito = "com.google.dexmaker:dexmaker-mockito:1.2"
val annotations = "com.android.support:support-annotations:$supportVersion"
val espresso = "com.android.support.test.espresso:espresso-core:2.2.2"
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-all.zip

0 comments on commit 470feb7

Please sign in to comment.