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

// Read credentials
def credentialFile = rootProject.file("credentials.properties")
def credentialProperty = new Properties()
credentialProperty.load(new FileInputStream(credentialFile))

android {
    compileSdkVersion androidCompileSdkVersion
    defaultConfig {
        applicationId "com.akshay.newsapp"
        minSdkVersion androidMinSdkVersion
        versionCode 4
        versionName "3.0.0"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        buildConfigField("String", "NEWS_API_KEY", credentialProperty['NEWS_API_KEY'])
        javaCompileOptions {
            annotationProcessorOptions {
                arguments += [
                    "room.schemaLocation": "$projectDir/schemas".toString(),
                    "room.incremental": "true"
                ]
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    sourceSets {
        // Share test utilities between unit and instrumented tests
        test.java.srcDirs += 'src/sharedTest/kotlin'
        androidTest.java.srcDirs += 'src/sharedTest/kotlin'
    }

    packagingOptions {
        // Exclude files not needed at runtime
        exclude "META-INF/**"
        exclude "*.txt"

        // Exclude Kotlin metadata
        exclude "**.kotlin_metadata"
        exclude "**.kotlin_builtins"
        exclude "**.kotlin_module"
    }

    buildFeatures {
        viewBinding true
    }
}

kapt {
    mapDiagnosticLocations = true
//    arguments {
//        arg("room.schemaLocation", roomSchemaDir)
//    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // Kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"

    // Kotlin Flow
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
    testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion"

    // Support Libraries
    implementation "androidx.appcompat:appcompat:$supportVersion"
    implementation "androidx.recyclerview:recyclerview:$recyclerViewVersion"
    implementation "androidx.cardview:cardview:$cardViewVersion"
    implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"

    // Retrofit
    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    implementation "com.squareup.okhttp3:logging-interceptor:$okHttpVersion"
    implementation "com.github.mrmike:ok2curl:$curlVersion"
    testImplementation "com.squareup.okhttp3:mockwebserver:$okHttpVersion"

    // Lifecycle (ViewModel + LiveData)
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$liveDataKtx"
    testImplementation "androidx.arch.core:core-testing:$archTestingVersion"

    // Room
    implementation "androidx.room:room-runtime:$roomVersion"
    kapt "androidx.room:room-compiler:$roomVersion"
    implementation "androidx.room:room-ktx:$roomVersion"
    androidTestImplementation "androidx.room:room-testing:$roomVersion"

    // Coil
    implementation "io.coil-kt:coil:$coilVersion"

    // Hilt + Dagger
    implementation "com.google.dagger:hilt-android:$hiltAndroidVersion"
    kapt "com.google.dagger:hilt-android-compiler:$hiltAndroidVersion"
    implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hiltViewModelVersion"
    kapt "androidx.hilt:hilt-compiler:$hiltViewModelVersion"

    // KTX
    implementation "androidx.core:core-ktx:$coreKtxVersion"
    implementation "androidx.fragment:fragment-ktx:$fragmentKtxVersion"

    // Testing
    testImplementation "junit:junit:$jUnitVersion"
    androidTestImplementation "androidx.test.ext:junit:$androidjUnitVersion"
    androidTestImplementation("androidx.test.espresso:espresso-core:$espressoVersion", {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$mockitoKotlinVersion"
    androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$mockitoKotlinVersion"

    // Debug
    implementation "com.jakewharton.timber:timber:$timberVersion"
}
