// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: 'extensions.gradle'

buildscript {
    ext.kotlin_version = '1.7.20'

    repositories {
        google()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath 'com.google.gms:google-services:4.3.14'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.vanniktech:gradle-maven-publish-plugin:0.22.0'
        classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.7.20'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    }
}

subprojects {
    if (name != 'sample') {
        apply plugin: "com.vanniktech.maven.publish"

        repositories {
            maven {
                url = version.toString().endsWith("SNAPSHOT")
                        ? 'https://oss.sonatype.org/content/repositories/snapshots/'
                        : 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
            }
        }
    }

    configurations.all {
        resolutionStrategy {
            // Force Kotlin to use current version
            force "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
            force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
            force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
            force "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
            force "org.jetbrains.kotlin:kotlin-android-extensions-runtime:$kotlin_version"
            force "junit:junit:4.13.2"
        }
    }

    afterEvaluate {
        // global dependencies for all modules
        dependencies {
            implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}