apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'kotlin-android'
apply plugin: 'org.jetbrains.dokka'

def githubUrl = 'https://github.com/francoiscampbell/CircleLayout'
def gitUrl = "${githubUrl}.git"
def gitTag = "v$version"

def projectFriendlyName = 'CircleLayout'
def projectDescription = 'An Android layout for arranging children along a circle'

group 'io.github.francoiscampbell'
version '0.3.0'

repositories {
    maven {
        url 'http://dl.bintray.com/francoiscampbell/maven'
    }
}

dependencies {
    testCompile 'junit:junit:4.12'
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
    }
}

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        minSdkVersion 1
        targetSdkVersion 24
        versionCode 1
        versionName version
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
}

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

//for dokka
//noinspection GroovyAssignabilityCheck
sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

dokka {
    outputFormat = 'javadoc'
    outputDirectory = "$buildDir/javadoc"
}

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

artifacts {
    archives javadocJar
    archives sourcesJar
}

task installAndBintrayUpload(dependsOn: [install, bintrayUpload]) {
}

bintrayUpload.shouldRunAfter install

install {
    repositories.mavenInstaller {
        pom.project {
            name projectFriendlyName
            description projectDescription
            url githubUrl
            inceptionYear '2016'

            packaging 'aar'
            groupId project.group
            artifactId project.name
            version project.version

            licenses {
                license {
                    name 'BSD 2-Clause'
                    url 'https://opensource.org/licenses/BSD-2-Clause'
                    distribution 'repo'
                }
            }
            scm {
                connection gitUrl
                url githubUrl

            }
            developers {
                developer {
                    name 'Francois Campbell'
                    email 'campbell.francois@gmail.com'
                }
            }
        }
    }
}

bintray {
    user = project.BINTRAY_USER
    key = project.BINTRAY_KEY

    configurations = ['archives']
    publish = true
    pkg {
        repo = 'maven'
        name = "$project.group:$project.name"
        licenses = ['BSD 2-Clause']
        vcsUrl = gitUrl
        //noinspection GroovyAssignabilityCheck
        version {
            name = project.version
            desc = projectDescription
            released = new Date()
            vcsTag = gitTag
        }
    }
}