buildscript {
    repositories {
        // maven { url "http://mvnrepo.alibaba-inc.com/mvn/repository" }
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
    }
}

apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven'
apply plugin: 'com.github.dcendents.android-maven'

allprojects {
    repositories {
        // maven { url "http://mvnrepo.alibaba-inc.com/mvn/repository" }
        mavenCentral()
        jcenter()
    }
}

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        consumerProguardFiles 'proguard-rules.pro'
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    sourceSets {
        main {
            assets.srcDirs = ['assets']
            jniLibs.srcDir(['libs'])
            java {
                srcDirs = ["src/main/java"];
            }
        }
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

// DO NOT EDIT BELOW THIS LINE
def siteUrl='https://github.com/weex-plugins/weex-amap'
def gitUrl='https://github.com/weex-plugins/weex-amap.git'
def userId = "&userId&"
def userKey = "&userKey&"
def developerId = "&developerId&"
def developerName = "&developerName&"
def developerEmail = "&developerEmail&"
def shouldPublish = false

group = "&group&"
version = "&version&"
// DO NOT EDIT ABOVE THIS LINE

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                name 'weex_amap'
                url siteUrl
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id developerId
                        name developerName
                        email developerEmail
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl
                }
            }
        }
    }
}

dependencies {
    // optional
    testCompile 'junit:junit:4.12'
    testCompile('org.robolectric:robolectric:2.4') {
        exclude module: 'commons-logging'
        exclude module: 'httpclient'
    }
    compile 'com.android.support:appcompat-v7:23.1.1'
    provided 'com.taobao.android:weex_sdk:0.10.0'
    provided 'com.amap.api:map3d-native:4.1.3'
    provided 'com.amap.api:map3d:4.1.3'
    provided 'com.amap.api:location:3.3.0'
}

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

artifacts {
    archives sourcesJar
}

bintray {
    user = userId
    key = userKey
    configurations = ['archives']
    pkg {
        repo = "maven"
        name = "weex_amap"
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = shouldPublish
    }
}

android.libraryVariants.all { variant ->
    def name = variant.name.capitalize()
    println variant.javaCompile.classpath.files
    if(variant.name == 'release') {
        task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
            // title = ''
            // description = ''
            source = variant.javaCompile.source
            classpath = files(variant.javaCompile.classpath.files, project.android.getBootClasspath())
            options {
                encoding "utf-8"
                links "http://docs.oracle.com/javase/7/docs/api/"
                linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference"
            }
            exclude '**/BuildConfig.java'
            exclude '**/R.java'
        }
        task("javadoc${variant.name.capitalize()}Jar", type: Jar, dependsOn: "generate${variant.name.capitalize()}Javadoc") {
            classifier = 'javadoc'
            from tasks.getByName("generate${variant.name.capitalize()}Javadoc").destinationDir
        }
        artifacts {
            archives tasks.getByName("javadoc${variant.name.capitalize()}Jar")
        }
    }

    // Ugly kludge to rename license files in the bundled commons-cli
    // dependency so that they do not appear to describe Stetho's license.
//    configurations.compile.each {
//        if (it.getName() == 'commons-cli-1.2.jar') {
//            def depJarPath = it.getPath()
//            task "tidyCommonsCli${name}"(type: Copy) {
//                from zipTree(depJarPath)
//                into "build/commons-cli-tidy-${name}"
//                rename 'LICENSE', 'commons-cli-LICENSE'
//                rename 'NOTICE', 'commons-cli-NOTICE'
//            }
//        }
//    }

    task "metainf${name}"(type: Copy) {
        from rootProject.file('LICENSE')
        into "build/metainf-${name}/META-INF"
    }

    task "fatjar${name}"(type: Jar, dependsOn: [ "jar${name}", "tidyCommonsCli${name}", "metainf${name}" ]) {
        classifier = 'fatjar'
        from variant.javaCompile.destinationDir
        from "build/commons-cli-tidy-${name}"
        from "build/metainf-${name}"
    }
}