@@ -116,23 +116,24 @@ allprojects {
116116subprojects {
117117 apply { plugin(" io.sentry.spotless" ) }
118118
119- // Mockito 5 and mockito-kotlin 5+ are built for Java 11. Test code is never published, so it
120- // compiles for at least Java 11 while the published code keeps its own target. Runs in
121- // afterEvaluate, as most modules pin the JVM target of all their compile tasks.
122- afterEvaluate {
123- tasks.withType<JavaCompile >().matching { it.name.contains(" Test" ) }.configureEach {
124- if (JavaVersion .toVersion(targetCompatibility) < JavaVersion .VERSION_11 ) {
125- sourceCompatibility = JavaVersion .VERSION_11 .toString()
126- targetCompatibility = JavaVersion .VERSION_11 .toString()
127- }
128- }
129- tasks.withType< org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile > ().matching { it.name.contains(" Test" ) }.configureEach {
130- if (compilerOptions.jvmTarget.get() < org.jetbrains.kotlin.gradle.dsl.JvmTarget .JVM_11 ) {
131- compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget .JVM_11 )
119+ // Mockito 5 and mockito-kotlin 5+ are built for Java 11, so test code (never published) can't
120+ // share the Java 8 target of the published code; it compiles for the build JDK instead.
121+ // Registered once each plugin is applied, so this afterEvaluate runs after the plugins and the
122+ // module have pinned the JVM target of all compile tasks.
123+ listOf (" java" , " com.android.library" , " com.android.application" ).forEach { pluginId ->
124+ plugins.withId(pluginId) {
125+ afterEvaluate {
126+ val isTestTask = { task: Task -> task.name.contains(" Test" ) && ! task.name.contains(" AndroidTest" ) }
127+ tasks.withType<JavaCompile >().matching(isTestTask).configureEach {
128+ sourceCompatibility = JavaVersion .VERSION_21 .toString()
129+ targetCompatibility = JavaVersion .VERSION_21 .toString()
130+ }
131+ tasks.withType< org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile > ().matching(isTestTask).configureEach {
132+ compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget .JVM_21 )
133+ }
132134 }
133135 }
134136 }
135-
136137 listOf (" com.android.library" , " com.android.application" ).forEach { pluginId ->
137138 plugins.withId(pluginId) {
138139 // Robolectric's SDK 37 sandbox (the default, as targetSdk is 37) reflectively writes
0 commit comments