buildscript {
    ext.kotlinVersion = '1.2.71'
    ext.agpVersion = '3.2.0'

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:$agpVersion"
        classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        classpath 'de.mobilej.unmock:UnMockPlugin:0.6.5'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }

    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:unchecked"
    }
}

ext {
    compileSdkVersion = 28
    targetSdkVersion = compileSdkVersion
    minSdkVersion = 14

    buildToolsVersion = '28.0.3'

    junitVersion = '4.12'
    assertjVersion = '3.6.2'
    lintVersion = "26" + agpVersion.substring(1)
    kotlinMockitoVersion = '1.5.0'
    unmockVersion = 'org.robolectric:android-all:4.3_r2-robolectric-0'
    testRuleVersion = '1.0.1'
    espressoVersion = '3.0.1'
    assertjAndroidVersion = '1.1.1'
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.10.2'
    distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}

subprojects { subproject ->
    // avoids conflicts in test app
    configurations.all {
        resolutionStrategy.force "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"

        // Replace deprecated Kotlin JRE dependencies with JDK dependencies
        resolutionStrategy.dependencySubstitution {
            all { DependencySubstitution dependency ->
                if (dependency.requested instanceof ModuleComponentSelector && dependency.requested.group == 'org.jetbrains.kotlin') {
                    if (dependency.requested.module == 'kotlin-stdlib-jre7') {
                        dependency.useTarget "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
                    }
                    if (dependency.requested.module == 'kotlin-stdlib-jre8') {
                        dependency.useTarget "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
                    }
                }
            }
        }
    }
}