apply plugin: 'com.android.library'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        consumerProguardFiles 'proguard-consumer.pro'
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
}

dependencies {
    implementation 'commons-cli:commons-cli:1.2'
    implementation 'com.google.code.findbugs:jsr305:3.0.2'
    implementation 'androidx.annotation:annotation:1.1.0'

    // Optional: reflection is used to test whether Fragment (and the transient AndroidX Core) are actually present.
    implementation 'androidx.appcompat:appcompat:1.2.0' // optional

    testImplementation 'junit:junit:4.12'
    testImplementation('org.robolectric:robolectric:2.4') {
        exclude module: 'commons-logging'
        exclude module: 'httpclient'
    }
    testImplementation 'org.powermock:powermock-api-mockito:1.6.6'
    testImplementation 'org.powermock:powermock-module-junit4:1.6.6'
}

apply from: rootProject.file('release.gradle')

android.libraryVariants.all { variant ->
    def name = variant.name.capitalize()

    // Ugly kludge to rename license files in the bundled commons-cli
    // dependency so that they do not appear to describe Stetho's license.
    task "tidyCommonsCli${name}"(type: Copy) {
        from {
            variant.javaCompile.classpath.findAll {
                it.getName() == 'commons-cli-1.2.jar'
            }.collect {
                zipTree(it)
            }
        }
        into "build/commons-cli-tidy-${name}"
        rename 'LICENSE', 'commons-cli-LICENSE'
        rename 'NOTICE', 'commons-cli-NOTICE'
    }

    task "metainf${name}"(type: Copy) {
        from rootProject.file('LICENSE')
        into "build/metainf-${name}/META-INF"
    }

    task "fatjar${name}"(type: Jar, dependsOn: [ "jar${name}", "tidyCommonsCli${name}", "metainf${name}" ]) {
        classifier = 'fatjar'
        from variant.javaCompile.destinationDir
        from "build/commons-cli-tidy-${name}"
        from "build/metainf-${name}"
        exclude "android/support/**/*"
    }
}
