@@ -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