buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
    }
}

apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'signing'

repositories {
    jcenter()
}

android {
    publishNonDefault true

    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        versionCode 13
        versionName "1.3"
        minSdkVersion 16
        targetSdkVersion 23
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    // Avoid 'duplicate files during packaging of APK' errors
    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'org.wordpress:utils:1.10.0'

    // Test libraries
    testCompile 'junit:junit:4.11'
    testCompile 'org.mockito:mockito-core:1.10.19'
    testCompile 'org.robolectric:robolectric:3.0'

    // Workaround for IDE bug
    // http://stackoverflow.com/questions/22246183/android-studio-doesnt-recognize-espresso-classes
    provided 'junit:junit:4.11'
    provided 'org.mockito:mockito-core:1.10.19'
}

signing {
    required {
        project.properties.containsKey("signing.keyId") && project.properties.containsKey("signing.secretKeyRingFile")
    }
    sign configurations.archives
}

version android.defaultConfig.versionName
group = "org.wordpress"
archivesBaseName = "editor"

// http://central.sonatype.org/pages/gradle.html

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

            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
                authentication(userName: project.properties.ossrhUsername, password: project.properties.ossrhPassword)
            }

            snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
                authentication(userName: project.properties.ossrhUsername, password: project.properties.ossrhPassword)
            }

            pom.project {
                name 'WordPress-Android-Editor'
                packaging 'aar'
                description 'A reusable Android rich text editor component'
                url 'https://github.com/wordpress-mobile/WordPress-Android-Editor'
                scm {
                    connection 'scm:git:https://github.com/wordpress-mobile/WordPress-Android-Editor.git'
                    developerConnection 'scm:git:https://github.com/wordpress-mobile/WordPress-Android-Editor.git'
                    url 'https://github.com/wordpress-mobile/WordPress-Android-Editor'
                }

                licenses {
                    license {
                        name 'The MIT License (MIT)'
                        url 'http://opensource.org/licenses/MIT'
                    }
                }

                developers {
                    developer {
                        id 'maxme'
                        name 'Maxime Biais'
                        email 'maxime@automattic.com'
                    }
                }
            }
        }
    }
}

//
// Testing
//

android.testOptions.unitTests.all {
    include '**/*Test.class'
    exclude '**/ApplicationTest.class'
}
