plugins {
    id 'com.android.library'
    id 'com.google.dagger.hilt.android'
}

android {
    compileSdkVersion 33
    buildToolsVersion "33.0.1"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"
    }
    namespace "dagger.hilt.android.simple.earlyentrypoint"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    testOptions {
        unitTests.includeAndroidResources = true
    }
}

hilt {
    enableTransformForLocalTests = true
    enableAggregatingTask = true
}

// This is a regression test for https://github.com/google/dagger/issues/2789.
// Reproducing this issue requires that we don't have unexpected tests, so this
// check validates that. In particular, if we accidentally add a test with no
// test-specific bindings the EarlyEntryPoints will use the component for that
// test instead of generating a component just for the EarlyEntryPoints, which
// causes this issue.
task checkSourceSetTask(){
    sourceSets {
        test {
            def actualSrcs = allSource.files.name as Set
            def expectedSrcs = [
                'EarlyEntryPointWithBindValueTest.java',
                'EarlyEntryPointWithBindValueObjects.java'
            ] as Set
            if (!actualSrcs.equals(expectedSrcs)) {
                throw new StopExecutionException(
                    'Unexpected test sources: ' + allSource.files.name)
            }
        }
    }
}

gradle.projectsEvaluated {
    preBuild.dependsOn checkSourceSetTask
}

dependencies {
    implementation "com.google.dagger:hilt-android:$dagger_version"
    annotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"

    testImplementation 'com.google.truth:truth:1.0.1'
    testImplementation 'junit:junit:4.13'
    testImplementation 'org.robolectric:robolectric:4.11.1'
    testImplementation 'androidx.core:core:1.3.2'
    testImplementation 'androidx.test.ext:junit:1.1.3'
    testImplementation 'androidx.test:runner:1.4.0'
    testImplementation "com.google.dagger:hilt-android-testing:$dagger_version"
    testAnnotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"
}
