apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'

project.ext.meta.vcsUrl = "https://github.com/alibaba/GCanvas.git"
version = project.version
buildscript {
    repositories {
        //本地库，local repository(${user.home}/.m2/repository)
        jcenter()
        mavenCentral()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
    }
}

def pomConfig = {
    url "https://g-platform.github.io"
    scm {
        url "https://github.com/alibaba/GCanvas"
        connection "scm:git:https://github.com/alibaba/GCanvas.git"
        developerConnection "scm:git:git@github.com:alibaba/GCanvas.git"
    }
    licenses {
        license {
            name 'Apache 2.0'
            url 'https://www.apache.org/licenses/LICENSE-2.0'
            distribution 'repo'
        }
    }

    developers {
        developer {
            name "ertong"
            email "soandky@gmail.com"
            organization "alibaba"
            organizationUrl "https://www.alibaba.com/"
        }

        developer {
            name "jwxbond"
            email "jwxbond@gmail.com"
            organization "alibaba"
            organizationUrl "https://www.alibaba.com/"
        }

        developer {
            name "sylonhu"
            organization "alibaba"
            organizationUrl "https://www.alibaba.com/"
        }

        developer {
            name "xieguanglei"
            email "xieguanglei@hotmail.com"
            organization "alibaba"
            organizationUrl "https://www.alibaba.com/"
        }

        developer {
            name "winter"
            organization "alibaba"
            organizationUrl "https://www.alibaba.com/"
        }
    }
}

publishing {
    println("$buildDir/outputs/aar/${project.name}-${version}.aar")
    publications {
        maven(MavenPublication) {
            groupId group
            artifactId project.ext.id
            version version
            println("${group}:${project.ext.id}:${version}")
            pom.withXml {
                def dependenciesNode = asNode().appendNode('dependencies')

                configurations.compile.allDependencies.each { dep ->
                    if (dep.group != null && (dep.name != null && "unspecified" != dep.name) && dep.version != null && dep.version != 'unspecified') {
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', dep.group)
                        dependencyNode.appendNode('artifactId', dep.name)
                        dependencyNode.appendNode('version', dep.version)
                    }
                }

                asNode().appendNode("name", "${project.group}:${project.ext.id}")

                asNode().appendNode("description", project.ext.meta.description)

                asNode().children().last() + pomConfig
            }
        }
    }
}

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

task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
    from androidJavadocs.destinationDir
    classifier = "javadoc"
}

artifacts {
    archives sourcesJar
    archives androidJavadocsJar
}

//上传到jcenter
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
    //读取 local.properties 文件里面的 bintray.user,对应的是https://bintray.com/signup/oss 的用户名
    user = properties.getProperty("bintray.user")  
     //读取 local.properties 文件里面的 bintray.apikey,对应的是https://bintray.com/signup/oss的api-key
    key = properties.getProperty("bintray.apikey")  
    configurations = ['archives']
    pkg {
        repo = "GCanvas"
        name = "${project.group}:${project.ext.id}"
        //读取 local.properties 文件里面的 bintray.user,对应的是https://bintray.com/signup/oss 的用户名
        userOrg = properties.getProperty("bintray.userOrg")
        licenses = ['Apache-2.0']
        websiteUrl = "https://g-platform.github.io"
        vcsUrl = project.ext.meta.vcsUrl
        labels = project.ext.meta.labels
        version {
            name = project.version
            desc = project.ext.meta.description
            vcsTag = project.version
        }
    }
}
