buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "com.github.dcendents:android-maven-gradle-plugin:$mavenPluginVersion"
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintrayPluginVersion"
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:$buildInfoPluginVersion"
    }
}

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

group = GROUP

// Both the artifactory and bintray plugins depend on this singular
// global `version` variable. As such, we need to configure it based
// on which task we're running.
//
// The solution here is brittle; it just checks whether 'bintrayUpload'
// was called for execution, otherwise it assumes SNAPSHOT. If we
// were to wait until the task graph was built, we'd be too late
// (the plugins would already have used `version`).
boolean isReleaseBuild = gradle.startParameter.taskNames.contains('bintrayUpload')
version = isReleaseBuild ? VERSION_NAME : "$VERSION_NAME-SNAPSHOT"
logger.info("RxAgera using version=$project.version")

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
    }

    compileOptions {
        sourceCompatibility rootProject.ext.sourceCompatibility
        targetCompatibility rootProject.ext.sourceCompatibility
    }
}

repositories {
    jcenter()
}

dependencies {
    compile "com.android.support:support-annotations:$androidSupportVersion"
    compile "io.reactivex:rxjava:$rxJavaVersion"
    compile "com.google.android.agera:agera:$ageraVersion"

    testCompile "junit:junit:$junitVersion"
}

// Create source/javadoc artifacts for publishing
apply from: "$rootDir/gradle/artifacts.gradle"

// Configure android-maven-gradle-plugin
install {
    repositories.mavenInstaller.pom.project {
        name POM_NAME
        description POM_DESCRIPTION
        packaging POM_PACKAGING
        url POM_URL

        licenses {
            license {
                name POM_LICENCE_NAME
                url POM_LICENCE_URL
                distribution POM_LICENCE_DIST
            }
        }

        scm {
            url POM_SCM_URL
            connection POM_SCM_CONNECTION
            developerConnection POM_SCM_DEV_CONNECTION
        }

        developers {
            developer {
                id 'akarnokd'
                name 'David Karnok'
            }
        }
    }
}

// Configure artifactory (for publishing snapshots)
//
// Based on NebulaOJOPublishingPlugin (from nebula-bintray-plugin)
artifactory {
    contextUrl = 'https://oss.jfrog.org'

    publish {
        repository {
            repoKey = 'oss-snapshot-local'

            if (project.hasProperty('bintrayUser')) {
                username = project.property('bintrayUser')
                password = project.property('bintrayKey')
            }
        }

        defaults {
            publishConfigs('archives')
        }
    }
}

// Configure gradle-bintray-plugin (for publishing releases)
bintray {
    configurations = ['archives']

    publish = true

    pkg {
        repo = 'RxAgera'
        name = 'RxAgera'
        userOrg = 'com.github.akarnokd'
        licenses = ['Apache-2.0']
        labels = ['rxjava', 'agera']
        websiteUrl = 'https://github.com/akarnokd/RxAgera/'
        issueTrackerUrl = 'https://github.com/akarnokd/RxAgera/issues'
        vcsUrl = 'https://github.com/akarnokd/RxAgera.git'
    }
}

if (project.hasProperty('bintrayUser') && project.hasProperty('bintrayKey')) {
    bintray.user = project.bintrayUser
    bintray.key = project.bintrayKey
}

if (project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')) {
    def sync = bintray.pkg.version.mavenCentralSync
    sync.sync = true
    sync.user = project.sonatypeUsername
    sync.password = project.sonatypePassword
}

apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'

afterEvaluate {
    def javaCompile = project.android.libraryVariants.toList().first().javaCompile
    androidJavadocs.classpath += javaCompile.classpath
    androidJavadocs.classpath += javaCompile.outputs.files
}
