// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: rootDir.toString() + '/config.gradle'
apply from: rootDir.toString() + '/build_module.gradle'

buildscript {
    repositories {
        maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
        maven { url "https://mirrors.tencent.com/repository/maven/thirdparty-snapshots/" }
        maven { url "https://repo1.maven.org/maven2" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.1'
        classpath "com.bihe0832.android:GradleDependenciesCheck:4.1.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10"
    }
}

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

allprojects {
    repositories {
        maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" }
        maven { url "https://mirrors.tencent.com/repository/maven/thirdparty-snapshots/" }
        maven { url "https://repo1.maven.org/maven2" }
        maven { url = uri("./../aafRepo/") }
    }

    afterEvaluate { Project subproject ->
        if (subproject.name == rootProject.name) {

            subproject.getTasks().register("showPublishCommand") {
                group = "zixieDev"
                doLast {
                    zixiePublishCommand()
                }
            }
            rootProject.getTasks().register("showInfo") {
                group = "zixieDev"
                doLast {
                    zixieHelpCommand
                }
            }

            rootProject.getTasks().register("mergeString") {
                group = "zixieDev"
                doLast {
                    zixieMergeStringCommand()
                }
            }
        }
    }
}


subprojects {
    apply plugin: 'com.bihe0832.gradleDependenciesCheck'

    GradleDependenciesCheckConfig {
        showResultType = 1
        excludePackage = "com.android.support;org.jetbrains.kotlin;android.arch.lifecycle"
    }

    afterEvaluate { Project subproject ->
        if (zixieIsDebug) println("subprojects afterEvaluate : " + subproject.name)

        zixieAutoDependencies(subproject.name)
        zixieLocalDependencies(subproject.name, subproject.getProjectDir().absolutePath + "/libs")

        subproject.getTasks().getByName('clean').doFirst {
            delete "build"
            delete ".externalNativeBuild"
        }

        if (subproject.name.startsWith("Lib") || subproject.name.startsWith("Common") || subproject.name.startsWith("Framework")) {

//            subproject.getTasks().create("copyAAR", Copy.class) {
//                group = "zixieDev"
//                from 'build/outputs/aar/' + module.name + '-release.aar'
//                into "./../libs/"
//            }

//            subproject.getTasks().getByName('publish').dependsOn("assembleRelease")
//            subproject.getTasks().getByName('copyAAR').dependsOn("assembleRelease")
        }
    }
}
