buildscript {
    ext.kotlin_version = '2.3.10'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.13.2'
        classpath 'com.google.gms:google-services:4.3.15'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'

subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')

    def setupAndroid = {
        if (project.plugins.hasPlugin('com.android.library') || project.plugins.hasPlugin('com.android.application')) {
            project.android {
                if (namespace == null || namespace == "") {
                    namespace = project.group
                }
                compileSdk 36
                defaultConfig {
                    targetSdk 36
                }
                compileOptions {
                    sourceCompatibility JavaVersion.VERSION_17
                    targetCompatibility JavaVersion.VERSION_17
                }
                if (project.hasProperty('kotlinOptions')) {
                    kotlinOptions {
                        jvmTarget = '17'
                    }
                }
                tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
                    kotlinOptions {
                        jvmTarget = "17"
                    }
                }
            }
        }
    }

    if (project.state.executed) {
        setupAndroid()
    } else {
        project.afterEvaluate {
            setupAndroid()
        }
    }
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}