Skip to content

Commit 1c7fbf3

Browse files
committed
build: Clarify the jvm-targets plugin comments and rename its helper
1 parent 6e81176 commit 1c7fbf3

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

‎build-logic/src/main/kotlin/io.sentry.jvm-targets.gradle.kts‎

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
22
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
33

4-
/**
5-
* Picks the JDK that compiles the code and runs the tests, and lifts test code off the Java 8
6-
* target that the published modules use.
7-
*/
4+
// Compilation and tests run on this JDK whatever JDK runs Gradle. Error Prone 2.50 ships Java 21
5+
// bytecode, so javac itself has to be 21; on JDK 17 it fails with "UnsupportedClassVersionError:
6+
// com/google/errorprone/ErrorProneJavacPlugin". This picks the JDK only - every module pins the
7+
// bytecode level it publishes itself.
88
val buildJdk = JavaLanguageVersion.of(21)
99

10-
// Compile and run tests on this JDK whatever JDK runs Gradle. Error Prone 2.50 ships Java 21
11-
// bytecode, so javac itself has to be 21; without a toolchain, building on JDK 17 fails with
12-
// "UnsupportedClassVersionError: com/google/errorprone/ErrorProneJavacPlugin".
13-
// This selects the JDK only; each module pins the bytecode level of its published code itself.
1410
plugins.withType<JavaBasePlugin> {
1511
extensions.configure<JavaPluginExtension> { toolchain { languageVersion.set(buildJdk) } }
1612
}
1713

18-
// Mockito 5 and mockito-kotlin 6 are built for Java 11, so test code (never published) can't share
19-
// the Java 8 target of the published code. The library modules pin main compilation only, so their
20-
// test tasks follow the toolchain on their own. Two groups can't do that and need the override
21-
// below: Android modules, because AGP applies compileOptions to every variant including the unit
22-
// tests, and the samples, which still pin every compile task and consume sentry-system-test-support.
23-
fun Project.followToolchainInTests(taskFilter: (Task) -> Boolean) {
24-
// Both languages have to move together or the Kotlin plugin rejects the mismatch. AGP sets these
25-
// task properties while creating the variants, so the override has to run after evaluation.
14+
/**
15+
* Targets [buildJdk] in the compile tasks that [taskFilter] selects. Both languages move together,
16+
* because the Kotlin plugin rejects a Java/Kotlin target mismatch.
17+
*/
18+
fun Project.applyToolchainToCompileTasks(taskFilter: (Task) -> Boolean) {
19+
// AGP assigns these task properties while it creates the variants, so this has to run later.
2620
afterEvaluate {
2721
tasks.withType<JavaCompile>().matching(taskFilter).configureEach {
2822
sourceCompatibility = buildJdk.toString()
@@ -36,7 +30,11 @@ fun Project.followToolchainInTests(taskFilter: (Task) -> Boolean) {
3630

3731
listOf("com.android.library", "com.android.application").forEach { pluginId ->
3832
plugins.withId(pluginId) {
39-
followToolchainInTests { it.name.contains("UnitTest") }
33+
// Mockito 5 and mockito-kotlin 6 are built for Java 11, so test code (never published) can't
34+
// share the Java 8 target of the published code. Other modules pin main compilation only, which
35+
// leaves their test tasks on the toolchain; AGP has no such split, as compileOptions applies to
36+
// every variant, so its unit tests need this.
37+
applyToolchainToCompileTasks { it.name.contains("UnitTest") }
4038

4139
// Robolectric's SDK 37 sandbox (the default, as targetSdk is 37) reflectively writes
4240
// FileDescriptor fields in ApplicationSharedMemory; without this, setup fails with

0 commit comments

Comments
 (0)