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

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 1
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
}

dependencies {
    compile 'com.android.support:support-annotations:20.0.0'
}

task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
}

task androidJavadocsJar(type: Jar) {
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

artifacts {
    archives androidSourcesJar
    archives androidJavadocsJar
}

if (project.hasProperty('sonatype.username') && project.hasProperty('sonatype.password')) {
    signing {
        sign configurations.archives
    }

    uploadArchives {
        repositories {
            mavenDeployer {
                beforeDeployment { deployment -> signing.signPom(deployment) }

                def repoUrl
                if (project.version.endsWith("SNAPSHOT")) {
                    repoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
                } else {
                    repoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
                }

                repository(url: repoUrl) {
                    authentication(
                            userName: project.getProperty('sonatype.username'),
                            password: project.getProperty('sonatype.password'))
                }

                pom.project {
                    name 'Holdr'
                    packaging 'aar'
                    description 'Generates view holders from Android layout files'
                    url 'https://github.com/evant/holdr'

                    scm {
                        url 'git@github.com:evant/holdr.git'
                        connection 'scm:git:git@github.com:evant/holdr.git'
                        developerConnection 'scm:git:git@github.com:evant/holdr.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 'evant'
                            name 'Evan Tatarka'
                        }
                    }
                }
            }
        }
    }
}
