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 18
        targetSdkVersion 30
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }

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

    lintOptions {
        abortOnError false
    }

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

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

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}


dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.31@jar"
    implementation "androidx.annotation:annotation:1.0.0"
    implementation 'com.alibaba:fastjson:1.2.26@jar'

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

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-JS'
            }
        }
    }
}
