apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'

allprojects {
    repositories {
        mavenLocal()
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

buildscript {

    ext.kotlin_version = '1.5.31'

    repositories {
        mavenLocal()
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }

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

android {

    // 不能升级，否则会碰到清单文件合并错误
    compileSdkVersion 30

    defaultConfig {
        minSdkVersion 21
        // 不能升级，否则会碰到清单文件合并错误
        targetSdkVersion 30
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }

    // https://www.jianshu.com/p/681589927f1f
    compileOptions {
        kotlinOptions.freeCompilerArgs += ['-module-name', "GaiaX-Adapter"]
    }

    lintOptions {
        abortOnError false
    }

    sourceSets {
        main {
            java.srcDirs = ['src/main/kotlin', 'src/main/java']
            jniLibs.srcDir 'src/main/jniLibs'
        }

        // https://stackoverflow.com/questions/26663539/configuring-res-srcdirs-for-androidtest-sourceset
        // https://stackoverflow.com/questions/23643189/android-gradle-src-androidtest-res-layout-mylayout-xml-not-found-in-mypackage-r
        androidTest {
            java.srcDirs = ['src/androidTest/java']
            res.srcDirs = ['src/androidTest/res']
            jniLibs.srcDir 'src/main/jniLibs'
        }
    }

    buildTypes {
        debug {
            debuggable true
        }
        release {
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    implementation "androidx.appcompat:appcompat:1.0.0"
    implementation "com.airbnb.android:lottie:4.1.0"
    implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.5.31@jar'
    implementation 'com.alibaba:fastjson:1.2.26@jar'

    if (System.getProperties().get("isGaiaXDemo") == "true") {
        compileOnly project(path: ':GaiaXAndroid')
    } else if (project.hasProperty("type") && project.getProperty("type").equals("release")) {
        compileOnly("com.github.alibaba.GaiaX:GaiaX:release-SNAPSHOT") { changing = true }
    } else {
        compileOnly("com.github.alibaba.GaiaX:GaiaX:dev-SNAPSHOT") { changing = true }
    }

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.annotation:annotation:1.0.0'
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0') {
        exclude group: 'javax.inject'
    }
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
}

afterEvaluate {
    publishing {
        publications {
            // Creates a Maven publication called "release".
            release(MavenPublication) {

                if (project.hasProperty("type")) {
                    if (project.getProperty("type").equals("release")) {
                        from components.release
                    } else {
                        from components.debug
                    }
                } else {
                    from components.debug
                }

                if (project.hasProperty("version")) {
                    version = project.getProperty("version")
                } else {
                    version = '0.0.0'
                }

                if (project.hasProperty("group")) {
                    groupId = project.getProperty("group")
                } else {
                    groupId = 'com.github.alibaba.GaiaX'
                }

                artifactId = 'GaiaX-Adapter'
            }
        }
    }
}