Campus-Capture/campus-capture

View on GitHub
app/build.gradle

Summary

Maintainability
Test Coverage
def getAPIKey(String label)
{
    def secretsFile = file("tokens.dat")
    try
    {
        def val = secretsFile.text.lines().find(s -> s.contains(label))
        if(val == null)
        {
            throw new GradleException("Specified local API key not found")
        }
        println("Reading key " + label + " from file")
        return val.split(':')[1].trim()
    }
    catch(FileNotFoundException ignored)
    {
        def val = System.getenv(label)
        if(val == null)
        {
            throw new GradleException("Specified CI API key not found")
        }
        println("Reading key " + label + " from Cirrus encrypted values")
        return System.getenv(label)
    }
}

plugins {
    id 'com.android.application'
    id 'jacoco'

    // Add the Google services Gradle plugin
    id 'com.google.gms.google-services'
    id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}

android {
    namespace 'com.github.campus_capture.bootcamp'
    compileSdk 33

    defaultConfig {
        applicationId "com.github.campus_capture.bootcamp"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        javaCompileOptions {
            annotationProcessorOptions {
                arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
            }
        }
    }

    buildTypes {
        release {
            resValue("string", "MAP_API_KEY", "\"" + getAPIKey("MAP_API_KEY") + "\"")
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            resValue("string", "MAP_API_KEY", "\"" + getAPIKey("MAP_API_KEY") + "\"")
            testCoverageEnabled true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildFeatures {
        viewBinding true
    }
    testOptions {
        unitTests.all {
            useJUnitPlatform()
        }
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation "androidx.fragment:fragment:1.5.5"
    implementation 'androidx.recyclerview:recyclerview:1.3.0'
    implementation "androidx.activity:activity-ktx:1.6.1"
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
    implementation 'androidx.navigation:navigation-fragment:2.5.3'
    implementation 'androidx.navigation:navigation-ui:2.5.3'
    implementation 'com.google.android.gms:play-services-maps:18.1.0'
    implementation 'com.google.maps.android:android-maps-utils:2.3.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.test.ext:junit:1.1.5'
    implementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation 'androidx.test.espresso:espresso-intents:3.5.1'
    implementation 'androidx.test.uiautomator:uiautomator:2.2.0'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'
    testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.1'
    androidTestImplementation 'com.adevinta.android:barista:4.2.0'
    androidTestImplementation 'androidx.test:runner:1.5.2'
    androidTestImplementation 'androidx.test:rules:1.5.0'
    debugImplementation "androidx.test:monitor:1.6.1"
    debugImplementation "androidx.fragment:fragment-testing:1.5.5"

    // Import the Firebase BoM
    implementation platform('com.google.firebase:firebase-bom:31.2.3')

    // When using the BoM, you don't specify versions in Firebase library dependencies

    // Add the dependency for the Firebase SDK for Google Analytics
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-database'

    // Also add the dependencies for firebase authentication
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-firestore'

    // Also add the dependency for the Google Play services library and specify its version
    implementation 'com.google.android.gms:play-services-auth:20.4.1'

    // Add Room library for SQLite compatibility
    def room_version = "2.5.1"
    implementation "androidx.room:room-runtime:$room_version"
    annotationProcessor "androidx.room:room-compiler:$room_version"
    // RxJava support for Room
    implementation "androidx.room:room-rxjava2:$room_version"
    // Guava support for Room, including Optional and ListenableFuture
    implementation "androidx.room:room-guava:$room_version"
    // Test helpers
    testImplementation "androidx.room:room-testing:$room_version"

    //Firebase authentication
    implementation 'com.firebaseui:firebase-ui-auth:7.2.0'


}

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

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

    def fileFilter = [
            '**/R.class',
            '**/R$*.class',
            '**/BuildConfig.*',
            '**/Manifest*.*',
            '**/*Test*.*',
            'android/**/*.*',
            '*databinding*'
    ]
    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: [
            'outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec',
            'outputs/code_coverage/debugAndroidTest/connected/*/coverage.ec'
    ]))
}

connectedCheck {
    finalizedBy jacocoTestReport
}