buildscript {
    ext.kotlin_version = '2.2.0'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.7.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

rootProject.buildDir = '../build'
subprojects {
    afterEvaluate { project ->
        if (project.extensions.findByName("android") != null) {
            Integer pluginCompileSdk = project.android.compileSdk
            if (pluginCompileSdk != null && pluginCompileSdk < 34) {

                def javaVersion = JavaVersion.VERSION_1_8
                project.android {
                    compileSdk 34
                    if (namespace == null) {
                        namespace project.group
                    }
                    compileOptions {
                        sourceCompatibility javaVersion
                        targetCompatibility javaVersion
                    }
                    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
                        kotlinOptions {
                            jvmTarget = javaVersion.toString()
                        }
                    }
                }
            }
        }
    }
    
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(":app")
}

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