buildscript {
    ext.kotlin_version = "1.7.20"
    repositories {
        google()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20'
        classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.5.3'
    }
}

plugins {
    id "org.jlleitschuh.gradle.ktlint" version "10.2.0"
    id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
    id("org.jetbrains.dokka") version "1.6.10"
}

allprojects {
    apply plugin: "org.jlleitschuh.gradle.ktlint" // Version should be inherited from parent

    ktlint {
        android = true
        ignoreFailures = false
        disabledRules = ["no-wildcard-imports", "import-ordering"]
        reporters {
            reporter "plain"
            reporter "checkstyle"
        }
        filter {
            exclude("**/generated/**")
            include("**/kotlin/**")
        }
    }

    repositories {
        google()
        maven { url "https://jitpack.io" }
        mavenCentral()
    }
}

subprojects {
    repositories {
        google()
        mavenCentral()
    }
    apply {
        plugin("org.jetbrains.dokka")
    }
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
        kotlinOptions {
            // Treat all Kotlin warnings as errors (disabled by default)
            allWarningsAsErrors = project.hasProperty("warningsAsErrors") ? project.warningsAsErrors : false

            freeCompilerArgs += '-Xopt-in=kotlin.RequiresOptIn'
            // Enable experimental coroutines APIs, including Flow
            freeCompilerArgs += '-Xopt-in=kotlin.Experimental'

            // Set JVM target to 1.8
            jvmTarget = "1.8"
        }
    }
}

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

apply from: 'git-hooks.gradle'
apply from: 'versions.gradle'
apply from: "${rootDir}/scripts/publish-root.gradle"
