buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}
apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'signing'

repositories {
    jcenter()
}

version "0.4.2"
group = "com.github.dkharrat.nexusdialog"

android {
    compileSdkVersion 25
    buildToolsVersion "27.0.3"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 23
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    libraryVariants.all { variant ->
        task("generate${variant.name}Javadoc", type: Javadoc) {
            description "Generates Javadoc for $variant.name."
            source = variant.javaCompile.source
            exclude '**/R.html', '**/R.*.html', '**/BuildConfig.java'
            doFirst {
                classpath =
                        files(variant.javaCompile.classpath.files,
                                project.android.getBootClasspath())
            }
        }
    }
}

dependencies {
    api fileTree(dir: 'libs', include: ['*.jar'])
    api 'com.android.support:appcompat-v7:25.3.1'
}

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

artifacts {
    archives sourcesJar
}

if (project.hasProperty('signing')) {
    signing {
        required { has("release") && gradle.taskGraph.hasTask("uploadArchives") }
        sign configurations.archives
    }
}

if (project.hasProperty('sonatypeUsername')) {
    uploadArchives {
        repositories.mavenDeployer {
            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

            repository(url: sonatypeRepo) {
                authentication(userName: sonatypeUsername, password: sonatypePassword)
            }

            pom.project {
                name 'NexusDialog'
                packaging 'aar'
                description 'Simple Form Builder for Android'
                url 'https://github.com/dkharrat/nexus-dialog'

                scm {
                    url 'scm:git@github.com:dkharrat/nexus-dialog.git'
                    connection 'scm:git@github.com:dkharat/nexus-dialog.git'
                    developerConnection 'scm:git@github.com:dkharrat/nexus-dialog.git'
                }

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

                developers {
                    developer {
                        id 'dkharrat'
                        name 'Dia Kharrat'
                        email 'dkharrat@gmail.com'
                    }
                }
            }
        }
    }
}
