apply plugin: 'com.android.library'
apply plugin: 'bintray-release'

ext {
    // Publishing
    poetryVersion = '3.0.1'
    poetryUserOrg = 'elastique'
    poetryWebsite = 'https://github.com/elastique/poetry'
    poetryGroupId = 'nl.elastique.poetry'
    poetryRepoName = 'poetry'
    poetryName = 'Elastique Poetry'

    // Libraries
    slf4jVersion = '1.7.+'
    ormliteVersion = '4.48'
    jacksonVersion = '2.3.+'
    androidSupportLibraryVersion = '23+'
    androidBuildToolsVersion = '23.0.2'
    androidTargetSdkVersion = 23
    androidCompileSdkVersion = 23
}

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7'
        classpath 'com.novoda:bintray-release:0.3.4'
        // bintray usage: ./gradlew clean build bintrayUpload -PbintrayUser=??? -PbintrayKey=??? -PdryRun=false
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile (
        [group: 'com.android.support', name: 'support-v4', version: androidSupportLibraryVersion],

        // ORM
        [group: 'com.j256.ormlite', name: 'ormlite-core', version: ormliteVersion],
        [group: 'com.j256.ormlite', name: 'ormlite-android', version: ormliteVersion],

        [group: 'org.slf4j' , name: 'slf4j-api' , version: slf4jVersion]

    )

    androidTestCompile(
        [group: 'org.apache.directory.studio', name: 'org.apache.commons.io', version: '2.4']
    )
}

android {
    compileSdkVersion androidCompileSdkVersion
    buildToolsVersion androidBuildToolsVersion

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion androidTargetSdkVersion
        testInstrumentationRunner 'android.test.InstrumentationTestRunner'
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/ASL2.0.txt'
        exclude 'LICENSE.txt'
        exclude 'LICENSE'
    }
}

android.libraryVariants.all { variant ->
    def name = variant.buildType.name
    if (name.equals('debug')) {
        return; // Skip debug builds.
    }
    def task = project.tasks.create "jar${name.capitalize()}", Jar
    task.dependsOn variant.javaCompile
    task.from variant.javaCompile.destinationDir
    artifacts.add('archives', task);
}

android.libraryVariants.all { variant ->
    task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
        title = poetryName
        description "Generates Javadoc for $variant.name."
        source = variant.javaCompile.source
        classpath = files(variant.javaCompile.classpath.files, project.android.getBootClasspath())
        options {
            links "http://docs.oracle.com/javase/7/docs/api/"
            linksOffline "https://d.android.com/reference","${android.sdkDirectory}/docs/reference"
        }
        exclude '**/BuildConfig.java'
        exclude '**/R.java'
    }
}

publish {
    userOrg = poetryUserOrg
    repoName = poetryRepoName
    groupId = poetryGroupId
    artifactId = 'poetry'
    version = poetryVersion
    description = poetryName
    website = poetryWebsite
}
