buildscript {
    repositories {
        mavenCentral()
        gradlePluginPortal()
        google()
    }

    apply from: 'dependencies.gradle'

    dependencies {
        classpath "com.android.tools.build:gradle:${versions.androidGradlePlugin}"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
        classpath "org.jetbrains.kotlinx:binary-compatibility-validator:${versions.binaryCompatibilityValidator}"
        classpath "org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokkaGradlePlugin}"
        classpath "org.jlleitschuh.gradle:ktlint-gradle:${versions.ktlintGradle}"
        classpath "com.diffplug.spotless:spotless-plugin-gradle:${versions.spotlessGradlePlugin}"
        classpath "org.jacoco:org.jacoco.core:${versions.jacocoGradlePlugin}"
        classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:${versions.atomicFuPlugin}"
        classpath "com.vanniktech:gradle-maven-publish-plugin:0.18.0"
        classpath "org.jetbrains.dokka:dokka-gradle-plugin:1.6.0"
        classpath "com.squareup.anvil:gradle-plugin:2.3.10"
        classpath "com.android.tools.build:gradle:7.0.0"
    }
}


apply from: 'dependencies.gradle'
apply plugin: 'binary-compatibility-validator'

apiValidation {
    ignoredProjects += [
        "integration-tests", "processor",
        "sample", "basic-scoping-sample", "sample-with-di", "app", "helloworldfeature"
    ]
}

allprojects {
    repositories {
        mavenCentral()
        google()
    }

    apply plugin: 'org.jlleitschuh.gradle.ktlint'
    ktlint {
        version = versions.ktlint
    }


    // Workaround to prevent Gradle from stealing focus from other apps during tests run/etc.
    // https://gist.github.com/artem-zinnatullin/4c250e04636e25797165
    tasks.withType(JavaForkOptions) {
        jvmArgs '-Djava.awt.headless=true'
    }

    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8

        kotlinOptions {
            jvmTarget = '1.8'
            freeCompilerArgs += ["-Xopt-in=kotlin.RequiresOptIn", '-Xjvm-default=compatibility']
        }
    }
}

subprojects { Project project ->
    project.plugins.withId('com.android.library') {
        project.android {
            compileSdkVersion versions.compileSdk

            defaultConfig {
                minSdkVersion versions.minSdk
                targetSdkVersion versions.targetSdk
                testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
            }

            compileOptions {
                sourceCompatibility JavaVersion.VERSION_1_8
                targetCompatibility JavaVersion.VERSION_1_8
            }
        }
    }

    apply plugin: 'com.diffplug.gradle.spotless'
    spotless {
        kotlin {
            target 'src/**/*.kt'
        }
    }
}

allprojects {
    plugins.withId("com.vanniktech.maven.publish") {
        mavenPublish {
            sonatypeHost = "S01"
        }
    }
}

tasks.register("printVersionName") {
    doLast {
        println VERSION_NAME
    }
}
