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

version = '0.8.3'
group = 'com.ebanx'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false

        // Bug in the android sdk https://github.com/square/okio/issues/58
        // remove this on android O (it will include the missing packages).
        warning 'InvalidPackage'
    }
}

gnag {
    checkstyle {
        enabled true
        reporterConfig project.file('checkstyle.xml')
    }
    pmd {
        enabled true
        reporterConfig project.file('pmd.xml')
    }
    findbugs {
        enabled false
    }
    androidLint {
        enabled true
        severity 'Error'
    }
    github {
        repoName 'ebanx/swipe-button'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.0.0'
    testCompile 'junit:junit:4.12'
}

if (project.hasProperty("android")) { // Android libraries
    task sourcesJar(type: Jar) {
        classifier = 'sources'
        from android.sourceSets.main.java.srcDirs
    }

    task javadoc(type: Javadoc) {
        source = android.sourceSets.main.java.srcDirs
        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    }
} else { // Java libraries
    task sourcesJar(type: Jar, dependsOn: classes) {
        classifier = 'sources'
        from sourceSets.main.allSource
    }
}

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

artifacts {
    archives javadocJar
    archives sourcesJar
}

install {
    repositories.mavenInstaller {
        pom.project {
            name 'SwipeButton'
            description 'A Button enabled by swipe'
            url 'https://github.com/ebanx/swipe-button/'
            inceptionYear '2017'

            packaging 'aar'
            groupId 'com.ebanx'
            artifactId 'swipe-button'
            version '0.8.3'

            licenses {
                license {
                    name 'The Apache Software License, Version 2.0'
                    url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    distribution 'repo'
                }
            }
            scm {
                connection 'git@github.com:ebanx/swipe-button.git'
                url 'https://github.com/ebanx/swipe-button/'

            }
            developers {
                developer {
                    name 'Leandro Borges Ferreira'
                }
            }
        }
    }
}

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

    publish = true

    pkg {
        repo = 'maven'
        name = 'swipe-button'
        userOrg = 'ebanx'
        licenses = ['Apache-2.0']
        labels = ['customview', 'spinner']
        websiteUrl = 'https://github.com/ebanx/swipe-button/'
        issueTrackerUrl = 'https://github.com/ebanx/swipe-button/issues'
        vcsUrl = 'https://github.com/ebanx/swipe-button.git'
        publicDownloadNumbers = true
    }

}

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

repositories {
    mavenCentral()
}
