import io.github.droidkaigi.feeder.Dep

buildscript {
    repositories {
        google()
        mavenCentral()
        // This snippet enables jcenter only for the dependencies described within the block.
        // Once they are on maven central you can just remove it.
        // https://github.com/Kotlin/kotlinx.html/issues/173#issuecomment-800504909
        jcenter {
            content {
                includeModule("org.jetbrains.kotlinx", "kotlinx-html-jvm")
                includeModule("org.jetbrains.kotlinx", "kotlinx-collections-immutable-jvm")
            }
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.0-rc01'
        classpath Dep.Kotlin.bom
        classpath Dep.Kotlin.plugin
        classpath Dep.Kotlin.stdlibJdk8
        classpath Dep.Kotlin.serializationPlugin
        classpath Dep.PlayServices.plugin
        classpath Dep.Dagger.plugin
        classpath Dep.FirebaseCrashlytics.plugin
        classpath Dep.exhaustivePlugin
        classpath Dep.SQLDelight.plugin
        classpath Dep.playServicesOssLicensesPlugin
        classpath Dep.buildKonfig
    }
}

plugins {
    id 'com.diffplug.spotless' version '5.7.0'
}


allprojects {
    repositories {
        google()
        mavenCentral()
        // This snippet enables jcenter only for the dependencies described within the block.
        // Once they are on maven central you can just remove it.
        // https://github.com/Kotlin/kotlinx.html/issues/173#issuecomment-800504909
        jcenter {
            content {
                includeModule("org.jetbrains.kotlinx", "kotlinx-html-jvm")
                includeModule("org.jetbrains.kotlinx", "kotlinx-collections-immutable-jvm")
            }
        }
        maven { url 'https://androidx.dev/snapshots/builds/6767375/artifacts/ui/repository' }
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }

    apply plugin: 'com.diffplug.spotless'
    spotless {
        ratchetFrom 'origin/main'
        kotlin {
            target '**/*.kt'
            targetExclude("$buildDir/**/*.kt")
            targetExclude('bin/**/*.kt')
            targetExclude("**/generated/**/*.kt")

            ktlint(Dep.ktlint.split(":").last())
                    .userData([android: "true", experimental: "true"])
        }
    }

    // FIXME: opt-on does not working in Android Studio
    def compilerArgs = [
            "-Xopt-in=kotlin.contracts.ExperimentalContracts",
            "-Xopt-in=androidx.compose.material.ExperimentalMaterialApi",
            "-Xopt-in=androidx.compose.foundation.ExperimentalFoundationApi",
            "-Xopt-in=com.google.accompanist.pager.ExperimentalPagerApi",
            "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
            "-Xopt-in=kotlin.RequiresOptIn",
    ]
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
        kotlinOptions {
            jvmTarget = "1.8"
            compilerArgs.forEach { compilerArg ->
                freeCompilerArgs += compilerArg
            }
        }
    }
}

apply from: file('gradle/dependencyGraph.gradle')

wrapper {
    distributionType = Wrapper.DistributionType.ALL
}
