apply plugin: 'com.jfrog.bintray'

version = VERSION_NAME

// TODO region remove if android* works
task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    failOnError false // TODO figure out why this task keeps failing
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}
// endregion remove if android* works


task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
    classpath += files(ext.androidJar)
    failOnError false // TODO figure out why this task keeps failing
}

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

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

artifacts {
//    archives javadocJar
//    archives sourcesJar
    archives androidSourcesJar
    archives androidJavadocsJar
}

// Bintray
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")

    configurations = ['archives']
    pkg {
        repo = BINTRAY_REPO
        name = BINTRAY_NAME
        desc = LIBRARY_DESCRIPTION
        websiteUrl = POM_URL
        vcsUrl = POM_SCM_URL
        licenses = ALL_LICENSES
        publish = true
        publicDownloadNumbers = true
        version {
            desc = LIBRARY_DESCRIPTION
            gpg {
                sign = true // Determines whether to GPG sign the files. The default is false
                passphrase = properties.getProperty("bintray.gpg.password") // Optional. The passphrase for GPG signing'
            }
        }
    }
}