group = PROJ_GROUP
version = PROJ_VERSION
project.archivesBaseName = PROJ_ARTIFACTID

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

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

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += configurations.compile
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

javadoc {
    options{
        encoding "UTF-8"
        charSet 'UTF-8'
        author true
        version true
        links "http://docs.oracle.com/javase/7/docs/api"
        title PROJ_ARTIFACTID
    }
}

artifacts {
    archives sourcesJar
    archives javadocJar
}

install {
    repositories.mavenInstaller {
        pom.project {
            name PROJ_NAME
            description PROJ_DESCRIPTION
            url PROJ_WEBSITEURL
            inceptionYear '2016'

            packaging 'aar'
            groupId PROJ_GROUP
            artifactId PROJ_ARTIFACTID
            version PROJ_VERSION

            licenses {
                license {
                    name 'The Apache Software License, Version 2.0'
                    url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    distribution 'repo'
                }
            }
            scm {
                connection PROJ_VCSURL
                url PROJ_WEBSITEURL

            }
            developers {
                developer {
                    id DEVELOPER_ID
                    name DEVELOPER_NAME
                    email DEVELOPER_EMAIL
                }
            }
        }
    }
}

bintray {
    user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : project.property('BINTRAY_USER')
    key = project.hasProperty('bintrayKey') ? project.property('bintrayKey') : project.property('BINTRAY_KEY')

    configurations = ['archives']

    dryRun = false
    publish = true

    pkg {
        repo = 'maven'
        name = PROJ_NAME
        licenses = ['Apache-2.0']
        vcsUrl = PROJ_VCSURL
        websiteUrl = PROJ_WEBSITEURL
        issueTrackerUrl = PROJ_ISSUETRACKERURL
        publicDownloadNumbers = true
        version {
            name = PROJ_VERSION
            desc = PROJ_DESCRIPTION
            vcsTag = PROJ_VERSION

            gpg {
                sign = true
            }

            mavenCentralSync {
                sync = project.hasProperty('SONATYPE_USER') && project.hasProperty('SONATYPE_KEY')
                user = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : ""
                password = project.hasProperty('SONATYPE_PASS') ? project.property('SONATYPE_PASS') : ""
                close = '1'
            }
        }
    }
}

//以下内容用于发布SNAPSHOT版本，如果不需要可以移除。
//参考自：https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin

apply plugin: "com.jfrog.artifactory"
artifactory {
    contextUrl = 'http://oss.jfrog.org/artifactory' //The base Artifactory URL if not overridden by the publisher/resolver
    resolve {
        repository {
            repoKey = 'libs-release'
        }
    }
    publish {
        repository {
            repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to
            username = bintray.user
            password = bintray.key
            maven = true
        }
        defaults {
            //这里的名字和前面bintray.configurations的值一致即可，会将其包含的输出上传到jfrog上去
            publishConfigs('archives')
        }
    }
}