Skip to content

Commit fe4aa72

Browse files
jbachorikclaude
andcommitted
Fix Exec task environment and JDK resolution
Two critical fixes for Exec-based test tasks: 1. Defer executable resolution to execution time - Move testJavaExecutable() call from configuration to doFirst - CI sets JAVA_TEST_HOME at runtime, not visible at config time - Fixes JDK version mismatch (tests ran with build JDK not test JDK) 2. Explicitly pass through CI environment variables - Exec tasks don't inherit environment like Test tasks - Add LIBC, KEEP_JFRS, TEST_COMMIT, TEST_CONFIGURATION, SANITIZER - Fixes assumption failures in MuslDetectionTest and others Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent f46d282 commit fe4aa72

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

build-logic/conventions/src/main/kotlin/com/datadoghq/profiler/ProfilerTestPlugin.kt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ class ProfilerTestPlugin : Plugin<Project> {
141141
testTask.description = "Runs unit tests with the $configName library variant"
142142
testTask.group = "verification"
143143

144-
// Use JAVA_TEST_HOME if set, otherwise JAVA_HOME (with proper fallback and error handling)
145-
testTask.executable = PlatformUtils.testJavaExecutable()
146-
147144
// Dependencies
148145
testTask.dependsOn(project.tasks.named("compileTestJava"))
149146
testTask.dependsOn(testCfg)
@@ -156,6 +153,10 @@ class ProfilerTestPlugin : Plugin<Project> {
156153

157154
// Configure JVM arguments and test execution
158155
testTask.doFirst {
156+
// Set executable at execution time so environment variables (JAVA_TEST_HOME) are read correctly
157+
// (CI scripts export JAVA_TEST_HOME at runtime, not visible at Gradle configuration time)
158+
testTask.executable = PlatformUtils.testJavaExecutable()
159+
159160
val allArgs = mutableListOf<String>()
160161

161162
// Standard JVM args
@@ -218,6 +219,14 @@ class ProfilerTestPlugin : Plugin<Project> {
218219
testTask.environment("DDPROF_TEST_DISABLE_RATE_LIMIT", "1")
219220
testTask.environment("CI", project.hasProperty("CI") || System.getenv("CI")?.toBoolean() ?: false)
220221

222+
// Pass through CI environment variables that tests expect
223+
// (Exec tasks don't inherit environment automatically like Test tasks do)
224+
System.getenv("LIBC")?.let { testTask.environment("LIBC", it) }
225+
System.getenv("KEEP_JFRS")?.let { testTask.environment("KEEP_JFRS", it) }
226+
System.getenv("TEST_COMMIT")?.let { testTask.environment("TEST_COMMIT", it) }
227+
System.getenv("TEST_CONFIGURATION")?.let { testTask.environment("TEST_CONFIGURATION", it) }
228+
System.getenv("SANITIZER")?.let { testTask.environment("SANITIZER", it) }
229+
221230
// Sanitizer-specific conditions
222231
when (configName) {
223232
"asan" -> testTask.onlyIf { PlatformUtils.locateLibasan() != null }
@@ -244,15 +253,15 @@ class ProfilerTestPlugin : Plugin<Project> {
244253
runTask.description = "Run the unwinding validator application ($configName config)"
245254
runTask.group = "application"
246255

247-
// Use JAVA_TEST_HOME if set, otherwise JAVA_HOME (with proper fallback and error handling)
248-
runTask.executable = PlatformUtils.testJavaExecutable()
249-
250256
runTask.dependsOn(project.tasks.named("compileJava"))
251257
runTask.dependsOn(mainCfg)
252258

253259
val mainClasspath = sourceSets.getByName("main").runtimeClasspath + mainCfg
254260

255261
runTask.doFirst {
262+
// Set executable at execution time so environment variables are read correctly
263+
runTask.executable = PlatformUtils.testJavaExecutable()
264+
256265
val allArgs = mutableListOf<String>()
257266
allArgs.addAll(extension.standardJvmArgs.get())
258267
allArgs.addAll(extension.extraJvmArgs.get())
@@ -282,15 +291,15 @@ class ProfilerTestPlugin : Plugin<Project> {
282291
reportTask.description = "Generate unwinding report for CI ($configName config)"
283292
reportTask.group = "verification"
284293

285-
// Use JAVA_TEST_HOME if set, otherwise JAVA_HOME (with proper fallback and error handling)
286-
reportTask.executable = PlatformUtils.testJavaExecutable()
287-
288294
reportTask.dependsOn(project.tasks.named("compileJava"))
289295
reportTask.dependsOn(mainCfg)
290296

291297
val mainClasspath = sourceSets.getByName("main").runtimeClasspath + mainCfg
292298

293299
reportTask.doFirst {
300+
// Set executable at execution time so environment variables are read correctly
301+
reportTask.executable = PlatformUtils.testJavaExecutable()
302+
294303
project.file("${project.layout.buildDirectory.get()}/reports").mkdirs()
295304

296305
val allArgs = mutableListOf<String>()

0 commit comments

Comments
 (0)