apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: "de.mannodermaus.android-junit5"
apply plugin: 'com.antonchaynikov.oneclickpublish'
apply plugin: 'com.apollographql.apollo'

def props = new Properties()
def secretFile = rootProject.file("secrets/keys.properties")
if (secretFile.exists())
    secretFile.withInputStream { props.load(it) }

detekt {
    toolVersion = "$versions.detekt"
    input = files("src/main/java")
    config = files("../default-detekt-config.yml")
}

android {
    compileSdkVersion versions.TARGET_SDK_VERSION

    defaultConfig {
        applicationId "com.flatstack.android"
        minSdkVersion versions.MIN_SDK_VERSION
        targetSdkVersion versions.TARGET_SDK_VERSION
        versionCode appVersionCode.toInteger()
        versionName appVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArgument "runnerBuilder",
                "de.mannodermaus.junit5.AndroidJUnit5Builder"
        buildConfigField 'String', 'BASE_URL', "\"https://rails-base-graphql-api.herokuapp.com/graphql\""

        oneClickPublish {
            branchNames = ["master"]  // branch names from which you can deploy, master by default
            remoteRepoName = "origin" // alias repository, origin by default
        }
    }
    signingConfigs {
        debug {
            storeFile file("$rootDir/debug.jks")
            storePassword "12345678"
            keyAlias "debug"
            keyPassword "12345678"
        }
        release {
            keyAlias props.getProperty('keyAlias')
            keyPassword props.getProperty('keyPassword')
            storeFile file("$rootDir/secrets/keystore.jks")
            storePassword props.getProperty('storePassword')
        }
    }
    buildTypes {
        release {
            ext.betaDistributionGroupAliases = "androidbase"
            ext.betaDistributionNotifications = true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
    sourceSets.each {
        it.java.srcDirs += "src/$it.name/kotlin"
    }
    testOptions {
        junitPlatform {
            filters {
                engines {
                    include 'spek2'
                }
            }
        }
    }
    lintOptions {
        warningsAsErrors true
        htmlOutput file("build/reports/lint/lint-report.html")
        xmlOutput file("build/reports/lint/lint-report.xml")
    }
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
    kotlinOptions {
        jvmTarget = '1.8'
        freeCompilerArgs = ['-Xjvm-default=enable',
                            "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
                            "-Xuse-experimental=kotlinx.coroutines.ObsoleteCoroutinesApi"]
    }
    androidExtensions {
        experimental = true
    }
}

apollo {
    generateKotlinModels.set(true)
}

repositories {
    maven { url = uri("https://dl.bintray.com/kodein-framework/Kodein-DI") }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$versions.kotlin"
    implementation 'com.google.code.gson:gson:2.8.6'

    implementation androidLibs
    implementation apolloLibs
    implementation coroutinesLibs
    implementation kodeinLibs
    implementation roomLibs
    kapt compilerLibs

    testImplementation unitTestLibs
    androidTestImplementation androidTestsLibs

    implementation platform('com.google.firebase:firebase-bom:25.12.0')
    implementation 'com.google.firebase:firebase-crashlytics-ktx'
    implementation 'com.google.firebase:firebase-analytics-ktx'

    testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:$versions.kotlin"
}
