import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '2.0.21'
    repositories {
        google()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.8.0'
        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.8.20'
    }
}

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

    //Support @JvmDefault
    tasks.withType(KotlinCompile).configureEach {
        kotlinOptions {
            freeCompilerArgs = ['-Xjvm-default=all', '-opt-in=kotlin.RequiresOptIn']
            jvmTarget = '1.8'
        }
    }
}

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'
            }
        }
    }

    afterEvaluate {
        android {
            compileSdkVersion 35

            defaultConfig {
                minSdkVersion 21
                targetSdkVersion 35
                versionCode 1
                versionName "$VERSION_NAME"
                testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
                vectorDrawables.useSupportLibrary = true
            }

            compileOptions {
                sourceCompatibility JavaVersion.VERSION_1_8
                targetCompatibility JavaVersion.VERSION_1_8
            }

            buildFeatures {
                buildConfig true
            }
        }
        configurations.configureEach {
            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"
            }
        }
        // global dependencies for all modules
        dependencies {
            implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
            testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
        }
    }
}

tasks.register('clean', Delete) {
    delete rootProject.layout.buildDirectory
}
