apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.mrozon.healthdiary"
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release {
            prepareProperties()
            storeFile configStoreFile
            storePassword configStorePassword
            keyAlias configKeyAlias
            keyPassword configKeyPassword
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        staging {
            minifyEnabled true
            signingConfig debug.signingConfig
        }
    }
    dataBinding {
        enabled = true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    lintOptions {
        ignoreTestSources true
        abortOnError true
        xmlReport false
        baselineFile file("$project.rootDir/config/baseline.xml")
        checkDependencies true
    }
}

apply from: "$project.rootDir/scripts/deps_versions.gradle"

dependencies {
    lintChecks project(':lint_repo')
    api project(':core_api')
    implementation project(':core')
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation dagger
    kapt daggerCompiler
    implementation navigationFragment
    implementation navigationUi
    implementation navigationDynamicFeatures
    implementation timber
    implementation constraintlayout
    implementation cardview
    implementation recyclerview
    implementation material

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.core:core-ktx:1.3.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation project(':utils')
    implementation project(':feature_splash')
    implementation project(':feature_auth')
    implementation project(':feature_person')
    implementation project(':feature_measure_type')
    implementation project(':feature_measure')
}

def prepareProperties() {
    Properties properties = new Properties()
    String filePath = ""
    if (System.getenv("HUDSON_HOME")!=null) {
        filePath = System.getenv("HUDSON_HOME") + "/.keystore/keystore.properties"
    } else {
        filePath = System.getenv("HOME") + "/.keystore/keystore.properties"
    }
    System.console().println(filePath)
    file(filePath).with { fname ->
        properties.load(fname.newDataInputStream())
        ext.configStoreFile = file(fname.getParent() + "/" + properties['keystore'])
        ext.configStorePassword = properties['keystore.password']
        ext.configKeyAlias = properties['keyAlias']
        ext.configKeyPassword = properties['keyPassword']
    }
}
