
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jetbrains.kotlin.kapt'
apply from: '../publishing.gradle'

sourceCompatibility = 1.8
targetCompatibility = 1.8

compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

configurations.all { strategy ->
    strategy.resolutionStrategy.force rootProject.deps.assertj, rootProject.deps.googleTestingCompile
}

dependencies {
    implementation deps.squareJavaPoet
    implementation deps.squareKotlinPoet
    implementation deps.kotlinPoetJavaInterop
    implementation deps.kotlinPoetKspInterop
    implementation deps.androidAnnotations
    implementation rootProject.deps.kotlinxMetadata
    implementation rootProject.deps.kotlinCoroutines
    implementation rootProject.deps.ksp

    // we shouldn't be including this technically, as it can cause issues with backwards compatibility,
    // but we use it for custom parsing of kotlin files to do resource scanning :(
    implementation rootProject.deps.kspImpl

    // Compiler needed to resolve resource references in annotations
    implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:$KOTLIN_VERSION"
    // This is included in kotlinCompileTesting, but the version can be out of date with our kotlin
    // compiler version, so we include it to force the right version
    testImplementation rootProject.deps.kotlinAnnotationProcessingEmbeddable
    implementation rootProject.deps.xProcessing

    testImplementation rootProject.deps.xProcessingTesting
    testImplementation "io.strikt:strikt-core:0.34.1"

    /** Provides the sun javac tools for looking up the R class trees. */
    compileOnly files(rootProject.file("libs/rt.jar"))
    compileOnly files(rootProject.file("libs/tools.jar"))
    // Allow us to use android support library annotations (@LayoutRes) in this project.
    // Since this isn't an android module normally we couldn't access them otherwise.
    compileOnly rootProject.deps.androidRuntime

    implementation project(':epoxy-annotations')
    compileOnly deps.incapRuntime
    kapt deps.incapProcessor

    testImplementation rootProject.deps.junit
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
    kotlinOptions {
        jvmTarget = "1.8"
        freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
        freeCompilerArgs += "-Xopt-in=kotlin.contracts.ExperimentalContracts"
        freeCompilerArgs += "-Xopt-in=androidx.room.compiler.processing.ExperimentalProcessingApi"
        freeCompilerArgs += "-Xopt-in=com.squareup.kotlinpoet.javapoet.KotlinPoetJavaPoetPreview"
        freeCompilerArgs += "-Xopt-in=com.squareup.kotlinpoet.ksp.KotlinPoetKspPreview"
    }
}
