//参考：https://raw.github.com/dm77/barcodescanner/master/build.gradle
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        //2.3.3 jitpack 发布用的版本
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
    }
}

allprojects {
//    group = GROUP
//    version = VERSION_NAME

    repositories {
        jcenter() //bintray的maven库
        mavenCentral() //sonatype的maven库
//        mavenLocal() //本地的maven库
        maven {
            url "https://www.jitpack.io" //jitpack的maven库
        }
        flatDir {
            dirs 'libs' //本地aar文件
        }
        google()
    }


    ext {
        isLibrary = false
        pomArtifactId = project.name
        pomVersion = VERSION_NAME
        pomDescription = 'This is library description'
    }

}

subprojects {
    afterEvaluate { Project project ->
        ext.pluginContainer = project.getPlugins()
        def hasAppPlugin = ext.pluginContainer.hasPlugin("com.android.application")
        def hasLibPlugin = ext.pluginContainer.hasPlugin("com.android.library")
        if (hasAppPlugin || hasLibPlugin) {
            android {
                compileSdkVersion COMPILE_SDK_VERSION as int
                buildToolsVersion BUILD_TOOL_VERSION
//                aaptOptions {
//                    cruncherEnabled = false
//                    useNewCruncher = false
//                }
                defaultConfig {
                    minSdkVersion MIN_SDK_VERSION as int
                    targetSdkVersion TARGET_SDK_VERSION as int
                    versionCode VERSION_CODE as int
                    versionName VERSION_NAME
                }

                buildTypes {
                    release {
                        debuggable false
                        minifyEnabled false //实时构建库项目时若启用混淆，APP模块引用会造成部分方法找不到
                    }
                    debug {
                        debuggable true
                        minifyEnabled false
                    }
                }
//                aaptOptions{
//                    cruncherEnabled false
//                    useNewCruncher false
//                }
                lintOptions {
                    abortOnError false
                }

                packagingOptions {
                    exclude 'META-INF/DEPENDENCIES.txt'
                    exclude 'META-INF/LICENSE.txt'
                    exclude 'META-INF/NOTICE.txt'
                    exclude 'META-INF/NOTICE'
                    exclude 'META-INF/LICENSE'
                    exclude 'META-INF/DEPENDENCIES'
                    exclude 'META-INF/notice.txt'
                    exclude 'META-INF/license.txt'
                    exclude 'META-INF/dependencies.txt'
                    exclude 'META-INF/LGPL2.1'
                    exclude 'META-INF/ASL2.0'
                }

            }
            dependencies {
                //自己项目加入版本覆盖依赖包的版本
                implementation "com.android.support:support-v4:${ANDROID_SUPPORT_VERSION}"
                implementation "com.android.support:support-annotations:${ANDROID_SUPPORT_VERSION}"
                implementation "com.android.support:appcompat-v7:${ANDROID_SUPPORT_VERSION}"
                implementation "com.android.support.constraint:constraint-layout:${CONSTRAINTLAYOUT}"
                implementation "com.blankj:utilcode:1.26.0"
            }
        }
//        if (project.isLibrary) {
//            configure(project) {
//                apply from: "${rootDir}/publish.gradle" //调用发布脚本
//            }
//        }

    }

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