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

repositories {
    mavenLocal()
    mavenCentral()
}

// This is the library version used when deploying the artifact
version = "0.0.2"
group = "no.agens"


def siteUrl = 'https://github.com/alexbirkett/android-cassowary-layout'      // Homepage URL of the library
def gitUrl = 'https://github.com/alexbirkett/android-cassowary-layout.git'   // Git repository URL

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName version
    }
}

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

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

    publications = ['mavenJava']
    dryRun = false //Whether to run this as dry-run, without deploying
    publish = true //If version should be auto published after an upload

    pkg {
        repo = "maven"
        name = "cassowary-layout"
        websiteUrl = siteUrl
        desc = 'An Android Layout that uses the Cassowary constraints resolving algorithm. An alternative to the Android common layouts: LinearLayout and RelativeLayout.'
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
        version {
            name = project.version
        }
    }
}

dependencies {
    compile "org.pybee:cassowary:0.0.1"
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifactId 'cassowary-layout'
            version version
            artifact(sourcesJar)
            artifact(javadocJar)
            artifact("$buildDir/outputs/aar/library-release.aar")
        }
    }
}

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))
}

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

artifacts {
    archives javadocJar
    archives sourcesJar
}

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.2.1'
}

tasks.withType(JavaCompile) { options.encoding = 'UTF-8' }