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

    dependencies {
        // START: FlutterFire Configuration
//        classpath 'com.google.gms:google-services:4.4.2'
//        // END: FlutterFire Configuration
//        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath 'com.google.gms:google-services:4.3.15'
        // END: FlutterFire Configuration
        classpath 'com.android.tools.build:gradle:8.11.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

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

    // Sync Kotlin JVM Target for ALL subprojects (works at task-config time)
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
        kotlinOptions {
            jvmTarget = "17"
        }
    }
}

// Force Java 17 on plugin subprojects AFTER they set their own defaults.
// Skip :app because it's already evaluated (via evaluationDependsOn) and already configured.
subprojects { sub ->
    if (sub.name != 'app') {
        sub.afterEvaluate {
            if (sub.hasProperty('android')) {
                sub.android {
                    compileOptions {
                        sourceCompatibility JavaVersion.VERSION_17
                        targetCompatibility JavaVersion.VERSION_17
                    }
                }
            }
        }
    }
}

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