OpenSRP/opensrp-client-anc

View on GitHub
opensrp-anc/build.gradle

Summary

Maintainability
Test Coverage
buildscript {
    repositories {
        mavenCentral()
        google()
        maven {
            url "https://s3.amazonaws.com/repo.commonsware.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'
        classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.0'
        classpath 'com.google.gms:google-services:4.3.14'
    }
    configurations.all {
        resolutionStrategy {
            eachDependency { details ->
                if ('org.jacoco' == details.requested.group) {
                    details.useVersion jacocoVersion
                }
            }
        }
    }
}
allprojects {

    subprojects {
        configurations.all {
            resolutionStrategy {
                eachDependency { details ->
                    if ('org.jacoco' == details.requested.group) {
                        details.useVersion jacocoVersion
                    }
                }
            }
        }
    }
}

apply plugin: 'com.android.library'
apply plugin: 'jacoco'

jacoco {
    toolVersion = jacocoVersion
}

android {
    /*
    * This allows running the app in the release variant. Make sure to add this configs to the
    * local.properties files when you need to use them
    * */
    if (project.rootProject.file("local.properties").exists()) {
        Properties properties = new Properties()
        properties.load(project.rootProject.file("local.properties").newDataInputStream())
        if (properties != null && properties.containsKey("store.file") && properties.containsKey("store.password") && properties.containsKey("key.password")) {
            signingConfigs {
                release {
                    storeFile file(properties['store.file'])
                    storePassword properties['store.password']
                    keyAlias = 'release'
                    keyPassword properties['key.password']
                }
                debug {
                    storeFile file(properties['store.file'])
                    storePassword properties['store.password']
                    keyAlias = 'release'
                    keyPassword properties['key.password']
                }
            }
        }
    }

    useLibrary 'org.apache.http.legacy'
    compileSdkVersion androidCompileSdkVersion
    buildToolsVersion androidBuildToolsVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion androidMinSdkVersion
        targetSdkVersion androidTargetSdkVersion
        versionCode Integer.parseInt(project.VERSION_CODE)
        versionName project.VERSION_NAME
        //buildConfigField "int", "VERSION_CODE", "'" + Integer.parseInt(project.VERSION_CODE) + "'"
        multiDexEnabled true
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

        if (properties != null && properties.containsKey("store.file") && properties.containsKey("store.password") && properties.containsKey("key.password")) {
            signingConfig signingConfigs.release
        }

        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath true
                arguments = [eventBusIndex: 'org.smartregister.anc.library.ANCEventBusIndex']
            }
        }
        if (project.rootProject.file("local.properties").exists()) {
            Properties properties = new Properties()
            properties.load(project.rootProject.file("local.properties").newDataInputStream())
            if (properties != null && properties.containsKey("flurry.api.key")) {
                buildConfigField "String", "FLURRY_API_KEY", properties["flurry.api.key"]
            } else {
                println("Flurry Analytics API key config variables is not set in your local.properties")
                buildConfigField "String", "FLURRY_API_KEY", "\"sample_key\""
            }

            if (properties != null && properties.containsKey("oauth.client.id")) {
                buildConfigField "String", "OAUTH_CLIENT_ID", properties["oauth.client.id"]

            } else {
                project.logger.error("oauth.client.id variable is not set in your local.properties")
                buildConfigField "String", "OAUTH_CLIENT_ID", "\"sample_client_id\""
            }


            if (properties != null && properties.containsKey("oauth.client.secret")) {
                buildConfigField "String", "OAUTH_CLIENT_SECRET", properties["oauth.client.secret"]

            } else {
                project.logger.error("oauth.client.secret variable is not set in your local.properties")
                buildConfigField "String", "OAUTH_CLIENT_SECRET", "\"sample_client_secret\""
            }
        } else {
            println("local.properties does not exist")
            buildConfigField "String", "FLURRY_API_KEY", "\"sample_key\""
            buildConfigField "String", "OAUTH_CLIENT_ID", "\"sample_client_id\""
            buildConfigField "String", "OAUTH_CLIENT_SECRET", "\"sample_client_secret\""
        }

        buildConfigField "String[]", "LOCATION_LEVELS", '{"Country", "Province", "District", "Facility", "Village"}'
        buildConfigField "String[]", "HEALTH_FACILITY_LEVELS", '{"Country", "Province", "District", "Health Facility", "Village"}'
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }

    lintOptions {
        lintConfig file("lint.xml")
        abortOnError false
    }

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

        debug {
            testCoverageEnabled true
        }
    }

    packagingOptions {
        exclude 'META-INF/*'
        exclude 'LICENSE.txt'
    }

    testOptions {
        unitTests {
            returnDefaultValues = true
            includeAndroidResources = true
        }
        unitTests.all {
            jvmArgs "-Xmx4g"
        }
    }

    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
}

tasks.withType(Test) {
    jacoco.includeNoLocationClasses = true
    jacoco.excludes = ['jdk.internal.*']
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation('org.smartregister:opensrp-client-native-form:3.1.1-SNAPSHOT@aar') {
        transitive = true
        exclude group: 'com.android.support', module: 'recyclerview-v7'
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'com.android.support', module: 'cardview-v7'
        exclude group: 'com.android.support', module: 'support-media-compat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'design'
        exclude group: 'org.yaml', module: 'snakeyaml'
        exclude group: 'io.ona.rdt-capture', module: 'lib'
    }
    implementation('org.smartregister:opensrp-client-core:6.0.0-SNAPSHOT@aar') {
        transitive = true
        exclude group: 'com.github.bmelnychuk', module: 'atv'
        exclude group: 'com.google.guava', module: 'guava'
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'net.zetetic', module: 'android-database-sqlcipher'
        exclude group: 'com.android.support', module: 'recyclerview-v7'
        exclude group: 'com.android.support', module: 'support-media-compat'
        exclude group: 'com.android.support', module: 'cardview-v7'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'design'
        exclude group: 'com.rengwuxian.materialedittext', module: 'library'
        exclude group: 'com.ibm.fhir', module: 'fhir-model'
        exclude group: 'org.smartregister', module: 'android-p2p-sync'
    }

    api("org.smartregister:android-p2p-sync:0.4.0-DEV-SNAPSHOT") {
        transitive = true
        exclude group: 'org.smartregister', module: 'opensrp-client-core'
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'org.smartregister', module: 'opensrp-client-native-form'
        exclude group: 'org.smartregister', module: 'opensrp-client-configurable-views'
        exclude group: 'com.rengwuxian.materialedittext', module: 'library'
    }

    implementation('org.smartregister:opensrp-client-configurable-views:1.1.5-SNAPSHOT@aar') {
        transitive = true
        exclude group: 'org.smartregister', module: 'opensrp-client-core'
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'com.android.support', module: 'recyclerview-v7'
        exclude group: 'com.android.support', module: 'support-media-compat'
        exclude group: 'com.android.support', module: 'cardview-v7'
        exclude group: 'com.android.support', module: 'support-v4'
    }
    implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9'
    implementation 'junit:junit:4.12'
    implementation 'androidx.test:core:1.4.0'
    annotationProcessor 'com.jakewharton:butterknife:10.2.3'
    implementation 'net.zetetic:android-database-sqlcipher:4.4.0@aar'
    implementation 'commons-validator:commons-validator:1.7'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'org.greenrobot:eventbus:3.2.0'
    annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.2.0'
    implementation 'com.google.guava:guava:30.0-jre'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    // Because RxAndroid releases are few and far between, it is recommended you also
    // explicitly depend on RxJava's latest version for bug fixes and new features.
    implementation 'io.reactivex.rxjava2:rxjava:2.2.20'
    implementation 'com.evernote:android-job:1.4.2'
    implementation 'com.github.lecho:hellocharts-library:1.5.8@aar'
    implementation 'id.zelory:compressor:2.1.1'
    implementation('com.google.android.material:material:1.4.0') {
        exclude group: 'com.android.support', module: 'recyclerview-v7'
        exclude group: 'com.android.support', module: 'cardview-v7'
    }

    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
    implementation group: 'org.yaml', name: 'snakeyaml', version: '1.27'
    implementation 'de.hdodenhof:circleimageview:3.1.0'
    implementation 'org.jeasy:easy-rules-core:3.3.0'
    implementation 'org.jeasy:easy-rules-mvel:3.3.0'
    implementation("com.itextpdf:itext7-core:7.1.12")
    implementation 'org.jacoco:org.jacoco.agent:0.7.9:runtime'
    testImplementation 'org.jacoco:org.jacoco.agent:0.7.9:runtime'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'org.jacoco:org.jacoco.agent:0.8.7:runtime'
    testImplementation 'org.jacoco:org.jacoco.agent:0.8.7:runtime'

    testImplementation 'junit:junit:4.13.1'
    testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3'
    testImplementation('com.squareup:fest-android:1.0.8') {
        exclude module: 'support-v4'
    }
    testImplementation 'org.robolectric:robolectric:4.4'
    testImplementation 'org.robolectric:shadows-multidex:4.4'
    testImplementation 'com.ibm.fhir:fhir-model:4.8.3'
    // https://mvnrepository.com/artifact/org.hamcrest/hamcrest
    testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2'
    //testImplementation 'org.robolectric:shadows-support-v4:3.4-rc2'
    testImplementation "org.powermock:powermock-module-junit4:2.0.7"
    testImplementation "org.powermock:powermock-module-junit4-rule:2.0.7"
    testImplementation "org.powermock:powermock-api-mockito2:2.0.7"
    testImplementation "org.powermock:powermock-classloading-xstream:2.0.7"
    testImplementation 'org.mockito:mockito-core:3.5.15'
    testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3'
    testImplementation 'org.skyscreamer:jsonassert:1.5.0'

    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0') {
        exclude group: 'com.google.code.findbugs'
    }
}

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', /*'createDebugCoverageReport'*/]) {
    reports {
        xml.enabled = true
        html.enabled = true
    }

    getReports().getXml().setDestination(file("${buildDir}/reports/jacoco/jacocoRootReport/merged.xml"))
    getReports().getHtml().setDestination(file("${buildDir}/reports/jacoco/jacocoRootReport/html"))

    def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*', '**/*$ViewBinder*.*']
    def debugTree = fileTree(dir: "$project.buildDir/intermediates/javac/debug/classes", excludes: fileFilter)
    def mainSrc = "$project.projectDir/src/main/java"
    sourceDirectories.setFrom(files([mainSrc]))
    classDirectories.setFrom(files([debugTree]))
    executionData.setFrom(fileTree(dir: project.buildDir, includes: [
            'jacoco/testDebugUnitTest.exec'
            //, 'outputs/code-coverage/connected/*coverage.ec', 'outputs/code-coverage/debugAndroidTest/connected/*coverage.ec'
    ]))
}

task printTasks {
    def projects = project.allprojects {}
    def reportT = project.tasks.withType(JacocoReport).findAll {
        it instanceof JacocoReport
    }

    println "PROJECT TASKS"
    def tSize = reportT.size()
    println "SIZE : $tSize"
    reportT.each {
        println "$it"
    }
}

task javadoc(type: Javadoc) {
    failOnError false
    def mainSrc = "$project.projectDir/src/main/java"
    source = files([mainSrc])
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    classpath += configurations.compile
}

def jacocoReportPath,sourceDirs

task coveralls {
    jacocoReportPath = "${buildDir}/reports/jacoco/jacocoTestReport/merged.xml"
    sourceDirs = ["$project.projectDir/src/main/java"]
}

apply from: '../maven.gradle'