Feature/switch to kotlin dsl (#595)

* Switch to using Kotlin in of groovy for the gradle configurations.

* Gradle file cleanup.

* Switch to using Kotlin in of groovy for the gradle configurations.

* Gradle file cleanup.

* Retrofit (and maybe others libs) requires java compile options 1.8, still backwards compatible.

* Prep for release 1.9.0-XXX

* Fix ktLint errors.
This commit is contained in:
Tim 2020-06-10 21:16:11 +02:00 committed by GitHub
parent 0b0670a04e
commit f87ed32560
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 387 additions and 288 deletions

View file

@ -1,135 +0,0 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.firebase.appdistribution'
apply plugin: 'com.github.triplet.play'
apply plugin: 'de.mannodermaus.android-junit5'
apply plugin: 'io.fabric'
buildscript {
repositories {
google()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.google.firebase:firebase-appdistribution-gradle:1.3.1'
classpath 'com.github.triplet.gradle:play-publisher:2.6.2'
classpath 'de.mannodermaus.gradle.plugins:android-junit5:1.5.2.0'
}
}
def vCode = "${System.env.VERSION_CODE ?: 1}".toInteger()
def vName = "1.9.0-${vCode}"
android {
compileSdkVersion projectSdkVersion.toInteger()
defaultConfig {
applicationId "io.homeassistant.companion.android"
minSdkVersion projectMinSdkVersion
targetSdkVersion 29
versionCode vCode
versionName vName
}
viewBinding {
enabled = true
}
firebaseAppDistribution {
serviceCredentialsFile = "firebaseAppDistributionServiceCredentialsFile.json"
releaseNotesFile = "app/src/main/play/release-notes/en-US/default.txt"
groups = "continuous-deployment"
}
signingConfigs {
release {
storeFile file('release_keystore.keystore')
storePassword "${System.env.KEYSTORE_PASSWORD ?: ""}"
keyAlias "$System.env.KEYSTORE_ALIAS" ?: ""
keyPassword "${System.env.KEYSTORE_ALIAS_PASSWORD ?: ""}"
v1SigningEnabled true
v2SigningEnabled true
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
release {
debuggable false
jniDebuggable false
zipAlignEnabled true
signingConfig signingConfigs.release
}
}
testOptions {
unitTests.returnDefaultValues = true
junitPlatform {
filters {
engines {
include 'spek2'
}
}
}
}
lintOptions {
disable 'MissingTranslation'
}
}
play {
serviceAccountCredentials = file("playStorePublishServiceCredentialsFile.json")
track = "beta"
resolutionStrategy = "ignore"
}
dependencies {
implementation project(':common')
implementation project(':domain')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
implementation "com.google.dagger:dagger:${daggerVersion}"
kapt "com.google.dagger:dagger-compiler:${daggerVersion}"
implementation "androidx.appcompat:appcompat:$appCompatVersion"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutversion"
implementation "androidx.recyclerview:recyclerview:$recyclerViewVersion"
implementation "androidx.preference:preference-ktx:1.1.0"
implementation 'com.google.android.material:material:1.1.0'
implementation("com.jakewharton.threetenabp:threetenabp:$threeTenAbpVersion") {
exclude group: 'org.threeten'
}
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation('com.lokalise.android:sdk:2.0.0-beta-5')
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation "com.google.firebase:firebase-core:17.2.2"
implementation "com.google.firebase:firebase-iid:20.0.2"
implementation "com.google.firebase:firebase-messaging:20.1.0"
implementation "androidx.work:work-runtime-ktx:2.3.2"
implementation 'androidx.biometric:biometric:1.0.1'
testImplementation "org.spekframework.spek2:spek-dsl-jvm:$spek2Version"
testImplementation "org.spekframework.spek2:spek-runner-junit5:$spek2Version"
testImplementation "org.assertj:assertj-core:$assertJVersion"
testImplementation "io.mockk:mockk:$mockkVersion"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion"
}
// This plugin must stay at the bottom
// https://developers.google.com/android/guides/google-services-plugin
apply plugin: 'com.google.gms.google-services'

139
app/build.gradle.kts Normal file
View file

@ -0,0 +1,139 @@
plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
id("kotlin-android-extensions")
id("com.google.firebase.appdistribution")
id("com.github.triplet.play") version "2.7.5"
id("io.fabric")
}
apply(plugin = "com.google.firebase.appdistribution")
buildscript {
repositories {
google()
maven(url = Config.Repository.gradle)
}
dependencies {
classpath(Config.Plugin.playPublisher)
classpath(Config.Plugin.androidJunit5)
}
}
android {
compileSdkVersion(Config.Android.compileSdk)
defaultConfig {
applicationId = "io.homeassistant.companion.android"
minSdkVersion(Config.Android.minSdk)
targetSdkVersion(Config.Android.targetSdk)
val envCode = System.getenv("VERSION_CODE")
val vCode = envCode?.toIntOrNull() ?: 1
versionCode = vCode
versionName = "${Config.version}-$vCode"
}
viewBinding {
isEnabled = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
firebaseAppDistribution {
serviceCredentialsFile = "firebaseAppDistributionServiceCredentialsFile.json"
releaseNotesFile = "app/src/main/play/release-notes/en-US/default.txt"
groups = "continuous-deployment"
}
signingConfigs {
create("release") {
storeFile = file("release_keystore.keystore")
storePassword = System.getenv("KEYSTORE_PASSWORD") ?: ""
keyAlias = System.getenv("KEYSTORE_ALIAS") ?: ""
keyPassword = System.getenv("KEYSTORE_ALIAS_PASSWORD") ?: ""
isV1SigningEnabled = true
isV2SigningEnabled = true
}
}
buildTypes {
named("debug").configure {
applicationIdSuffix = ".debug"
}
named("release").configure {
isDebuggable = false
isJniDebuggable = false
isZipAlignEnabled = true
signingConfig = signingConfigs.getByName("release")
}
}
testOptions {
unitTests.apply { isReturnDefaultValues = true }
}
tasks.withType<Test> {
useJUnitPlatform {
includeEngines("spek2")
}
}
lintOptions {
disable("MissingTranslation")
}
}
play {
serviceAccountCredentials = file("playStorePublishServiceCredentialsFile.json")
track = "beta"
resolutionStrategy = "ignore"
}
dependencies {
implementation(project(":common"))
implementation(project(":domain"))
implementation(Config.Dependency.Kotlin.core)
implementation(Config.Dependency.Kotlin.coroutines)
implementation(Config.Dependency.Kotlin.coroutinesAndroid)
implementation(Config.Dependency.Google.dagger)
kapt(Config.Dependency.Google.daggerCompiler)
implementation(Config.Dependency.AndroidX.appcompat)
implementation(Config.Dependency.AndroidX.lifecycle)
implementation(Config.Dependency.AndroidX.constraintlayout)
implementation(Config.Dependency.AndroidX.recyclerview)
implementation(Config.Dependency.AndroidX.preference)
implementation(Config.Dependency.Google.material)
implementation(Config.Dependency.Misc.threeTenAbp) {
exclude(group = "org.threeten")
}
implementation(Config.Dependency.Misc.crashlytics)
implementation(Config.Dependency.Misc.lokalize)
implementation(Config.Dependency.Play.location)
implementation(Config.Dependency.Firebase.core)
implementation(Config.Dependency.Firebase.iid)
implementation(Config.Dependency.Firebase.messaging)
implementation(Config.Dependency.AndroidX.workManager)
implementation(Config.Dependency.AndroidX.biometric)
testImplementation(Config.Dependency.Testing.spek2Jvm)
testImplementation(Config.Dependency.Testing.spek2JUnit)
testImplementation(Config.Dependency.Testing.assertJ)
testImplementation(Config.Dependency.Testing.mockk)
testImplementation(Config.Dependency.Kotlin.coroutinesTest)
}
// This plugin must stay at the bottom
// https://developers.google.com/android/guides/google-services-plugin
apply(plugin = "com.google.gms.google-services")

View file

@ -1,43 +0,0 @@
apply from: "gradle/dependencies.gradle"
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.31.2'
classpath "org.jlleitschuh.gradle:ktlint-gradle:9.1.1"
}
}
apply plugin: "org.jlleitschuh.gradle.ktlint"
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.lokalise.co' }
}
apply plugin: "org.jlleitschuh.gradle.ktlint"
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
task clean(type: Delete, group: 'build') {
delete rootProject.buildDir
}
ktlint {
android = true
}

45
build.gradle.kts Normal file
View file

@ -0,0 +1,45 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.jlleitschuh.gradle.ktlint") version "9.2.1"
}
buildscript {
repositories {
google()
jcenter()
maven(url = Config.Repository.fabric)
maven(url = Config.Repository.gradle)
}
dependencies {
classpath(Config.Plugin.android)
classpath(Config.Plugin.kotlin)
classpath(Config.Plugin.google)
classpath(Config.Plugin.appDistribution)
classpath(Config.Plugin.fabric)
classpath(Config.Plugin.ktlint)
}
}
allprojects {
repositories {
google()
jcenter()
maven(url = Config.Repository.lokalize)
}
tasks.withType<KotlinCompile>().configureEach {
println("Configuring $name in project ${project.name}...")
kotlinOptions {
jvmTarget = "1.8"
}
}
}
tasks.register("clean").configure {
delete("build")
}
ktlint {
android.set(true)
}

2
buildSrc/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.gradle
/build

View file

@ -0,0 +1,7 @@
repositories {
jcenter()
}
plugins {
`kotlin-dsl`
}

View file

@ -0,0 +1,100 @@
object Config {
const val version = "1.9.0"
object Plugin {
const val android = "com.android.tools.build:gradle:3.6.3"
const val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Dependency.Kotlin.version}"
const val google = "com.google.gms:google-services:4.3.3"
const val appDistribution = "com.google.firebase:firebase-appdistribution-gradle:1.4.0"
const val fabric = "io.fabric.tools:gradle:1.31.2"
const val ktlint = "org.jlleitschuh.gradle:ktlint-gradle:9.2.1"
const val playPublisher = "com.github.triplet.gradle:play-publisher:2.7.5"
const val androidJunit5 = "de.mannodermaus.gradle.plugins:android-junit5:1.6.0.0"
}
object Repository {
const val fabric = "https://maven.fabric.io/public"
const val gradle = "https://plugins.gradle.org/m2/"
const val lokalize = "https://maven.lokalise.co"
}
object Android {
const val compileSdk = 29
const val minSdk = 21
const val targetSdk = 29
}
object Dependency {
object Kotlin {
const val version = "1.3.72"
const val core = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${version}"
private const val coroutinesVersion = "1.3.3"
const val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${coroutinesVersion}"
const val coroutinesAndroid = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${coroutinesVersion}"
const val coroutinesTest = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${coroutinesVersion}"
}
object Google {
private const val daggerVersion = "2.27"
const val dagger = "com.google.dagger:dagger:${daggerVersion}"
const val daggerCompiler = "com.google.dagger:dagger-compiler:${daggerVersion}"
const val material = "com.google.android.material:material:1.1.0"
}
object AndroidX {
const val appcompat = "androidx.appcompat:appcompat:1.1.0"
const val lifecycle = "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
const val recyclerview = "androidx.recyclerview:recyclerview:1.1.0"
const val constraintlayout = "androidx.constraintlayout:constraintlayout:1.1.3"
const val preference = "androidx.preference:preference-ktx:1.1.1"
const val workManager = "androidx.work:work-runtime-ktx:2.3.4"
const val biometric = "androidx.biometric:biometric:1.0.1"
}
object Play {
const val location = "com.google.android.gms:play-services-location:17.0.0"
}
object Firebase {
const val core = "com.google.firebase:firebase-core:17.3.0"
const val iid = "com.google.firebase:firebase-iid:20.1.5"
const val messaging = "com.google.firebase:firebase-messaging:20.1.5"
}
object Square {
private const val retrofitVersion = "2.8.1"
const val retrofit = "com.squareup.retrofit2:retrofit:${retrofitVersion}"
const val retrofitJacksonConverter = "com.squareup.retrofit2:converter-jackson:${retrofitVersion}"
private const val okhttpVersion = "4.5.0"
const val okhttp = "com.squareup.okhttp3:okhttp:$okhttpVersion"
const val okhttpInterceptor = "com.squareup.okhttp3:logging-interceptor:$okhttpVersion"
const val okhttpMockServer = "com.squareup.okhttp3:mockwebserver:$okhttpVersion"
}
object Testing {
private const val assertJVersion = "3.13.2"
const val assertJ = "org.assertj:assertj-core:${assertJVersion}"
private const val mockkVersion = "1.9.3"
const val mockk = "io.mockk:mockk:${mockkVersion}"
const val spek2Version = "2.0.8"
const val spek2Jvm = "org.spekframework.spek2:spek-dsl-jvm:${spek2Version}"
const val spek2JUnit = "org.spekframework.spek2:spek-runner-junit5:${spek2Version}"
}
object Misc {
const val crashlytics = "com.crashlytics.sdk.android:crashlytics:2.10.1"
const val lokalize = "com.lokalise.android:sdk:2.0.0-beta-5"
const val jackson = "com.fasterxml.jackson.module:jackson-module-kotlin:2.10.1"
const val threeTenBp = "org.threeten:threetenbp:1.4.0"
const val threeTenAbp = "com.jakewharton.threetenabp:threetenabp:1.2.1"
const val javaxInject = "javax.inject:javax.inject:1"
}
}
}

View file

@ -1,25 +0,0 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion projectSdkVersion.toInteger()
defaultConfig {
minSdkVersion projectMinSdkVersion
}
}
dependencies {
implementation project(':domain')
implementation project(':data')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
implementation "com.google.dagger:dagger:${daggerVersion}"
kapt "com.google.dagger:dagger-compiler:${daggerVersion}"
implementation "com.squareup.retrofit2:retrofit:$retrofit2Version"
}

26
common/build.gradle.kts Normal file
View file

@ -0,0 +1,26 @@
plugins {
id("com.android.library")
id("kotlin-android")
id("kotlin-kapt")
}
android {
compileSdkVersion(Config.Android.compileSdk)
defaultConfig {
minSdkVersion(Config.Android.minSdk)
}
}
dependencies {
implementation(project(":domain"))
implementation(project(":data"))
implementation(Config.Dependency.Kotlin.core)
implementation(Config.Dependency.Kotlin.coroutines)
implementation(Config.Dependency.Google.dagger)
kapt (Config.Dependency.Google.daggerCompiler)
implementation(Config.Dependency.Square.retrofit)
}

View file

@ -1,35 +0,0 @@
apply plugin: 'java'
apply plugin: 'kotlin'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
test {
useJUnitPlatform {
includeEngines 'spek2'
}
}
dependencies {
implementation project(':domain')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
implementation 'javax.inject:javax.inject:1'
implementation "com.squareup.retrofit2:retrofit:$retrofit2Version"
implementation "com.squareup.retrofit2:converter-jackson:$retrofit2Version"
implementation "com.squareup.okhttp3:okhttp:$okhttp3Version"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3Version"
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion"
implementation "org.threeten:threetenbp:$threeTenBpVersion"
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp3Version"
testImplementation "org.spekframework.spek2:spek-dsl-jvm:$spek2Version"
testRuntimeOnly "org.spekframework.spek2:spek-runner-junit5:$spek2Version"
testImplementation "org.assertj:assertj-core:$assertJVersion"
testImplementation "io.mockk:mockk:$mockkVersion"
}

39
data/build.gradle.kts Normal file
View file

@ -0,0 +1,39 @@
plugins {
id("java")
id("kotlin")
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<Test> {
useJUnitPlatform {
includeEngines("spek2")
}
}
dependencies {
implementation(project(":domain"))
implementation(Config.Dependency.Kotlin.core)
implementation(Config.Dependency.Kotlin.coroutines)
implementation(Config.Dependency.Misc.javaxInject)
implementation(Config.Dependency.Square.retrofit)
implementation(Config.Dependency.Square.retrofitJacksonConverter)
implementation(Config.Dependency.Square.okhttp)
implementation(Config.Dependency.Square.okhttpInterceptor)
implementation(Config.Dependency.Misc.jackson)
implementation(Config.Dependency.Misc.threeTenBp)
testImplementation(Config.Dependency.Square.okhttpMockServer)
testImplementation(Config.Dependency.Testing.spek2Jvm)
testRuntimeOnly(Config.Dependency.Testing.spek2JUnit)
testImplementation(Config.Dependency.Testing.assertJ)
testImplementation(Config.Dependency.Testing.mockk)
}

View file

@ -1,23 +0,0 @@
apply plugin: 'java'
apply plugin: 'kotlin'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
test {
useJUnitPlatform {
includeEngines 'spek2'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
implementation 'javax.inject:javax.inject:1'
testImplementation "org.spekframework.spek2:spek-dsl-jvm:$spek2Version"
testRuntimeOnly "org.spekframework.spek2:spek-runner-junit5:$spek2Version"
testImplementation "org.assertj:assertj-core:$assertJVersion"
testImplementation "io.mockk:mockk:$mockkVersion"
}

27
domain/build.gradle.kts Normal file
View file

@ -0,0 +1,27 @@
plugins {
id("java")
id("kotlin")
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<Test> {
useJUnitPlatform {
includeEngines("spek2")
}
}
dependencies {
implementation(Config.Dependency.Kotlin.core)
implementation(Config.Dependency.Kotlin.coroutines)
implementation(Config.Dependency.Misc.javaxInject)
testImplementation(Config.Dependency.Testing.spek2Jvm)
testRuntimeOnly(Config.Dependency.Testing.spek2JUnit)
testImplementation(Config.Dependency.Testing.assertJ)
testImplementation(Config.Dependency.Testing.mockk)
}

View file

@ -1,22 +0,0 @@
ext {
projectSdkVersion = '29'
projectMinSdkVersion = '21'
androidxCoreVersion = '1.2.0'
lifecycleVersion = '2.2.0'
recyclerViewVersion = '1.1.0'
retrofit2Version = '2.6.2'
okhttp3Version = '4.2.2'
jacksonVersion = '2.10.1'
appCompatVersion = '1.1.0'
constraintLayoutversion = '1.1.3'
coroutinesVersion = '1.3.3'
daggerVersion = '2.25.2'
threeTenAbpVersion = '1.2.1'
threeTenBpVersion = '1.4.0'
assertJVersion = '3.13.2'
mockkVersion = '1.9.3'
spek2Version = '2.0.8'
}

View file

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View file

@ -1,4 +0,0 @@
include ':data',
':domain',
':common',
':app'

1
settings.gradle.kts Normal file
View file

@ -0,0 +1 @@
include(":data", ":domain", ":common", ":app")