apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

apply from: "$rootDir/buildsystem/dependencies.gradle"
apply from: "$rootDir/buildsystem/dokka.gradle"

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 2
        versionName kakao.version
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        main.res.srcDirs += 'src/main/res'
    }
}

repositories {
    jcenter()
    google()
}

dependencies {
    implementation libraries.kotlin_stdlib
    implementation libraries.appcompat
    implementation libraries.recyclerview
    implementation libraries.viewpager2
    implementation libraries.swiperefresh
    implementation libraries.design
    implementation libraries.espresso_core
    implementation libraries.espresso_web
    implementation libraries.espresso_intents
    implementation libraries.espresso_contrib
}

apply plugin: 'com.github.dcendents.android-maven'

group = kakao.group

install {
    repositories.mavenInstaller {
        pom.project {
            packaging 'aar'
            groupId kakao.group
            artifactId kakao.artifact

            name kakao.name
            description kakao.description
            url kakao.site

            licenses {
                license {
                    name 'The Apache Software License, Version 2.0'
                    url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                }
            }

            scm {
                connection kakao.github
                developerConnection kakao.github
                url kakao.site
            }
        }
    }
}

apply plugin: 'com.jfrog.bintray'

version = kakao.version

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

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

artifacts {
    archives javadocJar
    archives sourcesJar
}

bintray {
    user = System.getenv('BINTRAY_USER')
    key = System.getenv('BINTRAY_KEY')

    configurations = ['archives']

    pkg {
        repo = 'maven'
        name = kakao.name
        desc = kakao.description
        vcsUrl = kakao.github
        publish = true
        publicDownloadNumbers = true

        licenses = ['Apache-2.0']

        version {
            name = kakao.version
            desc = kakao.version_desc
            vcsTag = kakao.version
            released = new Date()
        }
    }
}

apply plugin: 'com.jfrog.artifactory'

artifactory {
    contextUrl = 'http://oss.jfrog.org/artifactory'

    publish {
        repository {
            repoKey = 'oss-snapshot-local'
            username = System.getenv('BINTRAY_USER')
            password = System.getenv('BINTRAY_KEY')
        }

        defaults {
            publishConfigs('archives')
            publishArtifacts = true
            publishPom = true
            publishIvy = false
            publishBuildInfo = false
        }
    }
}
