apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'org.jetbrains.kotlin.plugin.compose'

android {
    namespace "com.airbnb.android.showkase_processor_testing"
    // Added to avoid this error -
    // Execution failed for task ':showkase-processor-testing:mergeDebugAndroidTestJavaResource'.
    // > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
    // > More than one file was found with OS independent path 'META-INF/gradle/incremental.annotation.processors'
    packagingOptions {
        exclude 'META-INF/gradle/incremental.annotation.processors'
        exclude("META-INF/*.kotlin_module")
        // Added to avoid this error -
        // Execution failed for task ':app:mergeDebugAndroidTestJavaResource'.
        // > A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
        // > 2 files found with path 'META-INF/AL2.0' from inputs:
        exclude 'META-INF/AL2.0'
        exclude 'META-INF/LGPL2.1'
    }
    defaultConfig {
        minSdkVersion 26
        compileSdk 36
        targetSdkVersion 33
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        // The following argument makes the Android Test Orchestrator run its
        // "pm clear" command after each test invocation. This command ensures
        // that the app's state is completely cleared between tests.
        testInstrumentationRunnerArguments clearPackageData: 'true'
    }
    buildFeatures {
        compose true
    }
    configurations {
        all {
            // work around this error:
            // Duplicate class org.intellij.lang.annotations.Identifier found in modules annotations-12.0 (com.intellij:annotations:12.0) and annotations-13.0 (org.jetbrains:annotations:13.0)
            exclude group: "com.intellij", module: "annotations"
        }
    }
}

kotlin {
    jvmToolchain(17)
}

dependencies {
    // Allows this module to access the annotation processor related classes. Otherwise those are
    // only available in java library modules. Inspiration -
    // https://github.com/airbnb/epoxy/blob/master/epoxy-processortest/build.gradle
    testImplementation files('libs/rt.jar')

    // Support Libraries
    implementation deps.support.appCompat

    // Showkase
    implementation project(':showkase')
    implementation project(':showkase-processor')
    implementation project(':showkase-screenshot-testing')

    // KSP
    implementation deps.ksp

    // Compose
    implementation deps.compose.activityCompose
    implementation deps.compose.composeRuntime
    implementation deps.compose.core
    implementation deps.compose.foundation
    implementation deps.compose.tooling

    // Material
    implementation deps.material.material
    implementation deps.material.mdcComposeThemeAdapter

    // Testing
    testImplementation deps.test.assertJ
    testImplementation deps.test.googleTruth
    testImplementation deps.test.junit
    testImplementation deps.kotlinCompileTesting
    testImplementation deps.kotlinCompileTestingKsp
    testImplementation project(':showkase-screenshot-testing-paparazzi')
    testImplementation deps.test.paparazzi
}

// Needed for Java17 otherwise these tests failed to run locally.
// More info - https://youtrack.jetbrains.com/issue/KT-45545/Kapt-is-not-compatible-with-JDK-16
tasks.withType(Test) {
    if (JavaVersion.current() >= JavaVersion.VERSION_16) {
        jvmArgs(
                "--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
                "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
                "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
                "--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
                "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
                "--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
                "--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
                "--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
                "--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
                "--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
        )
    }
}
