Repository: square/okhttp
File: build.gradle.kts (Kotlin)

Code before:
  configure<CheckstyleExtension> {
    config = resources.text.fromArchiveEntry(checkstyleConfig, "google_checks.xml")
    toolVersion = rootProject.libs.versions.checkStyle.get()
    sourceSets = listOf(project.sourceSets["main"])
  }

  // Animal Sniffer confirms we generally don't use APIs not on Java 8.
  configure<AnimalSnifferExtension> {
    annotation = "okhttp3.internal.SuppressSignatureCheck"
    sourceSets = listOf(project.sourceSets["main"])
  }

  val signature: Configuration by configurations.getting
  dependencies {
    signature(rootProject.libs.signature.android.apilevel21)
    signature(rootProject.libs.codehaus.signature.java18)
  }

  tasks.withType<KotlinCompile> {
    kotlinOptions {
      jvmTarget = JavaVersion.VERSION_1_8.toString()
      freeCompilerArgs = listOf(
        "-Xjvm-default=all",
      )
    }
  }

  val platform = System.getProperty("okhttp.platform", "jdk9")
  val testJavaVersion = System.getProperty("test.java.version", "11").toInt()

  val testRuntimeOnly: Configuration by configurations.getting
  dependencies {
    testRuntimeOnly(rootProject.libs.junit.jupiter.engine)
    testRuntimeOnly(rootProject.libs.junit.vintage.engine)
  }

  tasks.withType<Test> {
    useJUnitPlatform()
    jvmArgs = jvmArgs!! + listOf(
      "-Dokhttp.platform=$platform",
      "-XX:+HeapDumpOnOutOfMemoryError"
    )

    if (platform == "loom") {
      jvmArgs = jvmArgs!! + listOf(
        "-Djdk.tracePinnedThread=full",
        "--enable-preview"
      )
    }

    val javaToolchains = project.extensions.getByType<JavaToolchainService>()

Review comment (suggestion):
Maybe worth a comment that we compile against 18 (in theory) or 11 (in practice) but then run against 8+?

As is the comment is confusing because 8+ and java18 contradict.

Code after:
  configure<CheckstyleExtension> {
    config = resources.text.fromArchiveEntry(checkstyleConfig, "google_checks.xml")
    toolVersion = rootProject.libs.versions.checkStyle.get()
    sourceSets = listOf(project.sourceSets["main"])
  }

  // Animal Sniffer confirms we generally don't use APIs not on Java 8.
  configure<AnimalSnifferExtension> {
    annotation = "okhttp3.internal.SuppressSignatureCheck"
    sourceSets = listOf(project.sourceSets["main"])
  }

  val signature: Configuration by configurations.getting
  dependencies {
    // No dependency requirements for testing-support.
    if (project.name == "okhttp-testing-support") return@dependencies

    if (project.name == "mockwebserver3-junit5") {
      // JUnit 5's APIs need java.util.function.Function and java.util.Optional from API 24.
      signature(rootProject.libs.signature.android.apilevel24) { artifact { type = "signature" } }
    } else {
      // Everything else requires Android API 21+.
      signature(rootProject.libs.signature.android.apilevel21) { artifact { type = "signature" } }
    }

    // OkHttp requires Java 8+.
    signature(rootProject.libs.codehaus.signature.java18) { artifact { type = "signature" } }
  }

  tasks.withType<KotlinCompile> {
    kotlinOptions {
      jvmTarget = JavaVersion.VERSION_1_8.toString()
      freeCompilerArgs = listOf(
        "-Xjvm-default=all",
      )
    }
  }

  val platform = System.getProperty("okhttp.platform", "jdk9")
  val testJavaVersion = System.getProperty("test.java.version", "11").toInt()

  val testRuntimeOnly: Configuration by configurations.getting
  dependencies {
    testRuntimeOnly(rootProject.libs.junit.jupiter.engine)
    testRuntimeOnly(rootProject.libs.junit.vintage.engine)
  }

  tasks.withType<Test> {
    useJUnitPlatform()
    jvmArgs = jvmArgs!! + listOf(
      "-Dokhttp.platform=$platform",