apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
apply plugin: 'jacoco'

android {
    compileSdkVersion 28

    defaultConfig {
        applicationId "com.github.goldy1992.hiltjacoco"
        minSdkVersion 28
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    hilt {
      //  enableTransformForLocalTests = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }

    testOptions {
        animationsDisabled true

        unitTests {
            includeAndroidResources = true
            returnDefaultValues = true
        }
    }
}

dependencies {

    debugImplementation group: 'androidx.activity', name: 'activity-ktx', version: ACTIVITY_VERSION
    debugImplementation group: 'androidx.core', name: 'core-ktx', version: ANDROIDX_CORE_KOTLIN_VERSION


    def HILT_VERSION = '2.28.3-alpha'
    def HILT_JETPACK_VERSION = '1.0.0-alpha02'

    // hilt
    implementation group: 'com.google.dagger', name: 'hilt-android', version: HILT_VERSION
    kapt group: 'com.google.dagger', name: 'hilt-android-compiler', version: HILT_VERSION

    testImplementation group: 'com.google.dagger', name: 'hilt-android-testing', version: HILT_VERSION
    kaptTest group: 'com.google.dagger', name: 'hilt-android-compiler', version: HILT_VERSION

    implementation group: 'androidx.hilt', name: 'hilt-lifecycle-viewmodel', version: HILT_JETPACK_VERSION
    kapt group: 'androidx.hilt', name: 'hilt-compiler', version: HILT_JETPACK_VERSION
    testImplementation group: 'androidx.hilt', name: 'hilt-lifecycle-viewmodel', version: HILT_JETPACK_VERSION
    kaptTest group: 'androidx.hilt', name: 'hilt-compiler', version: HILT_JETPACK_VERSION


    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'

    testImplementation("org.robolectric:robolectric:$ROBOLECTRIC_VERSION") {
        exclude group: "com.google.auto.service", module: "auto-service"
    }
   // testImplementation group: 'org.robolectric', name: 'shadows-supportv4', version: ROBOLECTRIC_VERSION


    testImplementation group: 'androidx.test', name: 'core', version: TEST_CORE_VERSION
    testImplementation junit5UnitTests
    testRuntimeOnly junit5UnitTestRuntime

}

task jacocoTestReportDebug(type: JacocoReport, dependsOn: ['test']) {

    jacoco {
        toolVersion = "$JACOCO_VERSION"
    }

    reports {
        xml.enabled = true
        html.enabled = true
    }

    def mainSrc = "$project.projectDir/src/main/java"
    def mainClasses = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug")

    sourceDirectories.from = files([mainSrc])
    classDirectories.from = files([mainClasses])
    executionData.from = "$project.buildDir/jacoco/testDebugUnitTest.exec"

    tasks.withType(Test) {
        jacoco.includeNoLocationClasses = true
    }
}