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

Properties properties = new Properties()
final def bintrayPropertiesFile = project.rootProject.file('bintray.properties')
if (bintrayPropertiesFile.exists()) properties.load(bintrayPropertiesFile.newDataInputStream())

android {
    compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
        consumerProguardFiles 'proguard-rules-consumer.pro'
    }

    dataBinding {
        enabled = true
    }
}

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

    configurations = ['archives']
    publications = ['aar']
    pkg {
        repo = "maven"
        name = project.POM_ARTIFACT_ID
        desc = project.POM_DESCRIPTION
        websiteUrl = project.POM_URL
        vcsUrl = project.POM_SCM_URL
        licenses = ["Apache-2.0"]
        publish = true

        version {
            gpg {
                sign = true
                passphrase = properties.getProperty("bintray.gpg.passphrase")
            }
            mavenCentralSync {
                sync = true
                user = properties.getProperty("oss.userToken")
                password = properties.getProperty("oss.userTokenValue")
                close = '1'
            }
        }
    }
}

project.ext {
    mavDevelopers = ["Fe": "Federico"]
    mavSiteUrl = "https://github.com/sky-uk/gradle-maven-plugin"
    mavGitUrl = mavSiteUrl + '.git'
    mavProjectName = 'GradleMavenizer'
    mavPublishToInternalRepo = true
    mavRepoInternalUrl = "path/to/internal/repo"
    mavLibraryLicenses = ["Apache-2.0": 'http://www.apache.org/licenses/LICENSE-2.0.txt']
    mavLibraryDescription = "A simple description of the project"
}

publishing {
    publications {
        aar(MavenPublication) {
            pom {
                packaging = 'aar'
                name = project.POM_NAME
                description = project.POM_DESCRIPTION
                url = project.POM_URL
                licenses {
                    license {
                        name = project.POM_LICENCE_NAME
                        url = project.POM_LICENCE_URL
                    }
                }
                developers {
                    developer {
                        id = project.POM_DEVELOPER_ID
                        name = project.POM_DEVELOPER_NAME
                        email = project.POM_DEVELOPER_EMAIL
                    }
                }
                scm {
                    connection = project.POM_SCM_URL
                    developerConnection = project.POM_SCM_CONNECTION
                    url = project.POM_URL
                }
            }
        }
    }
}

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

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

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

artifacts {
    archives javadocJar
    archives sourcesJar
}
