24
24
import org .elasticsearch .gradle .info .GlobalBuildInfoPlugin ;
25
25
import org .elasticsearch .gradle .test .ErrorReportingTestListener ;
26
26
import org .elasticsearch .gradle .util .Util ;
27
+ import org .gradle .api .Action ;
27
28
import org .gradle .api .GradleException ;
28
29
import org .gradle .api .JavaVersion ;
29
30
import org .gradle .api .Plugin ;
30
31
import org .gradle .api .Project ;
32
+ import org .gradle .api .Task ;
31
33
import org .gradle .api .artifacts .Configuration ;
32
34
import org .gradle .api .artifacts .ModuleDependency ;
33
35
import org .gradle .api .artifacts .ProjectDependency ;
@@ -241,20 +243,23 @@ public static void configureTestTasks(Project project) {
241
243
*/
242
244
SystemPropertyCommandLineArgumentProvider nonInputProperties = new SystemPropertyCommandLineArgumentProvider ();
243
245
244
- test .doFirst (t -> {
245
- project .mkdir (testOutputDir );
246
- project .mkdir (heapdumpDir );
247
- project .mkdir (test .getWorkingDir ());
248
- project .mkdir (test .getWorkingDir ().toPath ().resolve ("temp" ));
249
-
250
- // TODO remove once jvm.options are added to test system properties
251
-
252
- // TODO remove once jvm.options are added to test system properties
253
- if (BuildParams .getRuntimeJavaVersion () == JavaVersion .VERSION_1_8 ) {
254
- test .systemProperty ("java.locale.providers" , "SPI,JRE" );
255
- } else {
256
- test .systemProperty ("java.locale.providers" , "SPI,COMPAT" );
257
- test .jvmArgs ("--illegal-access=warn" );
246
+ // We specifically use an anonymous inner class here because lambda task actions break Gradle cacheability
247
+ // See: https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:how_does_it_work
248
+ test .doFirst (new Action <>() {
249
+ @ Override
250
+ public void execute (Task t ) {
251
+ project .mkdir (testOutputDir );
252
+ project .mkdir (heapdumpDir );
253
+ project .mkdir (test .getWorkingDir ());
254
+ project .mkdir (test .getWorkingDir ().toPath ().resolve ("temp" ));
255
+
256
+ // TODO remove once jvm.options are added to test system properties
257
+ if (BuildParams .getRuntimeJavaVersion () == JavaVersion .VERSION_1_8 ) {
258
+ test .systemProperty ("java.locale.providers" , "SPI,JRE" );
259
+ } else {
260
+ test .systemProperty ("java.locale.providers" , "SPI,COMPAT" );
261
+ test .jvmArgs ("--illegal-access=warn" );
262
+ }
258
263
}
259
264
});
260
265
@@ -276,7 +281,7 @@ public static void configureTestTasks(Project project) {
276
281
"-XX:+HeapDumpOnOutOfMemoryError"
277
282
);
278
283
279
- test .getJvmArgumentProviders ().add (() -> List . of ("-XX:HeapDumpPath=$heapdumpDir" ));
284
+ test .getJvmArgumentProviders ().add (new SimpleCommandLineArgumentProvider ("-XX:HeapDumpPath=" + heapdumpDir ));
280
285
281
286
String argline = System .getProperty ("tests.jvm.argline" );
282
287
if (argline != null ) {
0 commit comments