buildscript {
    repositories {
        mavenLocal()
        jcenter()
    }
    dependencies {
        classpath "com.taobao.android:atlasplugin:2.3.1.beta55"
    }
}

group = 'com.taobao.android.atlasdemo'
version = getEnvValue("versionName","1.0.0");
def apVersion = getEnvValue("apVersion","");

apply plugin: 'com.taobao.atlas.application'


//TODO do this in plugin
configurations {
    providedCompile
    all*.exclude group: 'com.android.support', module: 'multidex'
}

repositories {
    mavenLocal()
    jcenter()
}

dependencies {

    compile('com.android.support:appcompat-v7:23.1.0')

    compile('com.taobao.android:atlas_core:5.0.6@aar') {
        transitive = true
    }

    compile("com.taobao.android:firstbundle:${version}@awb")

    compile 'com.taobao.android:atlasupdate:1.1.4.2@aar'

    compile 'com.alibaba:fastjson:1.1.45.android@jar'

}


configurations.all {

    resolutionStrategy {
        cacheChangingModulesFor(0, 'SECONDS')
        force "com.google.android:support-v4:21.0.2";
    }
}

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.2"

    compileOptions.encoding = 'UTF-8'

    defaultConfig {
        versionName version
        multiDexEnabled true

        ndk {
            abiFilters "x86", "armeabi"  //默认只启用x86,armeabi
        }

        resConfigs "en", "fr"
    }

    dexOptions {
        jumboMode = true
        preDexLibraries = true
        // javaMaxHeapSize = '2048m'
    }

    buildTypes {
        debug {
            // debug模式
            multiDexEnabled true
        }

        release {
            multiDexEnabled true
            shrinkResources false
            // 是否进行混淆
            minifyEnabled true
            proguardFile 'proguard.cfg'
        }
    }

    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }

}

atlas {

    atlasEnabled true

    tBuildConfig {
        autoStartBundles = ['com.taobao.firstbundle'] //自启动bundle配置
    }


    patchConfigs{
        debug {
            createTPatch true
        }
    }


    buildTypes {
        debug {
            if (apVersion){
                baseApDependency   "com.taobao.android.atlasdemo:AP-debug:${apVersion}@ap"
                patchConfig    patchConfigs.debug
            }
        }
    }

}

task wrapper(type: Wrapper) {
    gradleVersion = '2.12'
    distributionUrl = 'http://services.gradle.org/distributions/gradle-2.12-all.zip'
}

apply plugin: 'maven'
apply plugin: 'maven-publish'

publishing {
    repositories {
        mavenLocal()
    }
}

publishing {
    publications {
        maven(MavenPublication) {
            artifact "${project.buildDir}/outputs/apk/${project.name}-debug.ap"
            artifactId "AP-debug"
        }
    }
}

String getEnvValue(key, defValue){
    def val = System.getProperty(key);
    if(null != val){
        return val;
    }
    val = System.getenv(key);
    if(null != val){
        return val;
    }
    return defValue;
}

tasks.whenTaskAdded { task ->
    if (task.name.contains("DebugAndroidTest")) {
        task.setEnabled(false);
    }
}
