buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
    }
}


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



android {
    def globalConfiguration = rootProject.extensions.getByName("ext")

    compileSdkVersion globalConfiguration.getAt("androidCompileSdkVersion")
    buildToolsVersion globalConfiguration.getAt("androidBuildToolsVersion")

    defaultConfig {
        minSdkVersion globalConfiguration.getAt("androidMinSdkVersion")
        targetSdkVersion globalConfiguration.getAt("androidTargetSdkVersion")

        applicationId globalConfiguration.getAt("androidApplicationId")
        versionCode globalConfiguration.getAt("androidVersionCode")
        versionName globalConfiguration.getAt("androidVersionName")
        testInstrumentationRunner globalConfiguration.getAt("testInstrumentationRunner")
        testApplicationId globalConfiguration.getAt("testApplicationId")

        generatedDensities = []
    }

    aaptOptions {
        additionalParameters "--no-version-vectors"
    }

    lintOptions {
        abortOnError false

    }


    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }

    signingConfigs {
        debug {
            storeFile file('../config/buildsystem/debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }

    buildTypes {
        debug {
            versionNameSuffix '-dev'
            applicationIdSuffix '.dev'
            signingConfig signingConfigs.debug
        }
    }

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def newApkName
            //If there's no ZipAlign task it means that our artifact will be unaligned and we need to mark it as such.
            if (output.zipAlign) {
                newApkName = appName + "-${variant.versionName}.apk"
            } else {
                newApkName = appName + "-${variant.versionName}-unaligned.apk"
            }
            output.outputFile = new File(output.outputFile.parent, newApkName)
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
}

dependencies {
    def presentationDependencies = rootProject.ext.presentationDependencies
    def presentationTestDependencies = rootProject.ext.presentationTestDependencies
    def dataDependencies = rootProject.ext.dataDependencies

    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    kapt presentationDependencies.daggerCompiler
    compile presentationDependencies.dagger
    compile presentationDependencies.supportRecyclerView
    compile presentationDependencies.supportCardView
    compile presentationDependencies.supportGridLayout
    compile presentationDependencies.supportDesign
    compile presentationDependencies.supportAppCompat
    compile presentationDependencies.rxJava
    compile presentationDependencies.rxAndroid
    compile presentationDependencies.glide
    compile presentationDependencies.rxKotlin

    provided presentationDependencies.javaxAnnotation

    compile dataDependencies.retrofit2
    compile dataDependencies.retrofit2Converter
    compile dataDependencies.retrofit2RxAdapter
    compile dataDependencies.gson
    compile dataDependencies.supportAnnotations
    compile dataDependencies.okHttpLoggingInterceptor


    androidTestCompile presentationTestDependencies.mockito
    androidTestCompile presentationTestDependencies.dexmaker
    androidTestCompile presentationTestDependencies.dexmakerMockito
    androidTestCompile presentationTestDependencies.espresso
    androidTestCompile presentationTestDependencies.espressoIntents
    androidTestCompile presentationTestDependencies.testingRunner
    androidTestCompile presentationTestDependencies.testingRules
    androidTestCompile presentationTestDependencies.supportAnnotations
}

kapt {
    generateStubs = true
}
