Skip to content

Commit 38288e8

Browse files
committed
build: Keep only the javac unit test targets inside afterEvaluate
1 parent 982954a commit 38288e8

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

‎build-logic/build.gradle.kts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ plugins {
44

55
repositories {
66
gradlePluginPortal()
7-
// AGP is only published to Google's repository.
87
google()
98
}
109

‎build-logic/src/main/kotlin/io/sentry/gradle/SentryCompilationPlugin.kt‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,19 @@ class SentryCompilationPlugin : Plugin<Project> {
7070
.toInt()
7171

7272
private fun Project.targetBuildJdkForUnitTests() {
73-
// AGP assigns these task properties when it creates the compile tasks, as they can be
74-
// variant aware, so right now there's no way around using afterEvaluate
73+
val unitTestTask = { task: Task -> task.name.contains("UnitTest") }
74+
// jvmTarget is a Property, so this set wins over the AGP convention whenever it runs.
75+
tasks.withType(KotlinJvmCompile::class.java).matching(unitTestTask).configureEach {
76+
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(BUILD_JDK.toString()))
77+
}
78+
// source/targetCompatibility are plain fields, so the last write wins, and AGP writes its
79+
// compileOptions while it creates the compile tasks. Registering earlier - at apply time or
80+
// in onVariants - is silently overwritten, so right now there's no way around afterEvaluate.
7581
afterEvaluate {
76-
val unitTestTask = { task: Task -> task.name.contains("UnitTest") }
7782
tasks.withType(JavaCompile::class.java).matching(unitTestTask).configureEach {
7883
sourceCompatibility = BUILD_JDK.toString()
7984
targetCompatibility = BUILD_JDK.toString()
8085
}
81-
tasks.withType(KotlinJvmCompile::class.java).matching(unitTestTask).configureEach {
82-
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(BUILD_JDK.toString()))
83-
}
8486
}
8587
}
8688
}

0 commit comments

Comments
 (0)