apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {

  defaultConfig {
    // Using 16 here as it is the minimum version of Paris, which we are restricted to.
    minSdkVersion 16
    compileSdk rootProject.COMPILE_SDK_VERSION
    targetSdkVersion rootProject.TARGET_SDK_VERSION
  }

  testOptions.unitTests.includeAndroidResources = true

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

    testOptions {
      unitTests {
        all {
          jvmArgs += [
              '--add-opens', 'jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
          ]
        }
      }
    }
}

configurations.all { strategy ->
  strategy.resolutionStrategy.force rootProject.deps.junit, rootProject.deps.robolectric,
      rootProject.deps.mockito
}

// Java files in the "resources" folder are not included in the build for some reason (seems like source files are skipped?)
// This files are needed to test the annotation processor, so we manually copy them into the build.
task('copyDebugTestResources', type: Copy) {
  from("${projectDir}/src/test/resources")
  into("${buildDir}/intermediates/sourceFolderJavaResources/debug")
}

task('copyReleaseTestResources', type: Copy) {
  from("${projectDir}/src/test/resources")
  into("${buildDir}/intermediates/sourceFolderJavaResources/release")
}

preBuild.dependsOn copyReleaseTestResources
preBuild.dependsOn copyDebugTestResources

dependencies {
  implementation project(':epoxy-adapter')
  implementation project(':epoxy-modelfactory')
  implementation rootProject.deps.paris
  implementation rootProject.deps.androidRecyclerView

  kapt project(':epoxy-processor')

  // Need to include the processors directly since we create an instance of it in code for testing
  testImplementation project(':epoxy-processor')
  testImplementation rootProject.deps.ksp
  testImplementation rootProject.deps.parisProcessor

  testImplementation project(':epoxy-processortest')
  testImplementation "io.github.java-diff-utils:java-diff-utils:4.5"
  testImplementation rootProject.deps.kotlinCompileTesting
  testImplementation "io.strikt:strikt-core:0.31.0"
  testImplementation rootProject.deps.googleTestingCompile
  testImplementation rootProject.deps.junit
  testImplementation rootProject.deps.robolectric
  testImplementation files(rootProject.file("libs/rt.jar"))
  testImplementation files(rootProject.file("libs/tools.jar"))

  // 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
}
