diff --git a/plugin/src/main/java/org/gradle/testretry/TestRetryTaskExtension.java b/plugin/src/main/java/org/gradle/testretry/TestRetryTaskExtension.java
index 40ef332..a048a6d 100644
--- a/plugin/src/main/java/org/gradle/testretry/TestRetryTaskExtension.java
+++ b/plugin/src/main/java/org/gradle/testretry/TestRetryTaskExtension.java
@@ -19,6 +19,8 @@
import org.gradle.api.provider.Property;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.testing.Test;
+import org.gradle.process.JavaForkOptions;
+import org.jetbrains.annotations.Nullable;
/**
* Allows configuring test retry mechanics.
@@ -91,6 +93,13 @@ public interface TestRetryTaskExtension {
*/
void filter(Action super Filter> action);
+ /**
+ * Invoked when test are retried.
+ */
+ void onRetry(Action super JavaForkOptions> action);
+
+ @Nullable Action super JavaForkOptions> getOnRetry();
+
/**
* A filter for specifying which tests may be retried.
*
diff --git a/plugin/src/main/java/org/gradle/testretry/internal/config/DefaultTestRetryTaskExtension.java b/plugin/src/main/java/org/gradle/testretry/internal/config/DefaultTestRetryTaskExtension.java
index 0bf185b..013c089 100644
--- a/plugin/src/main/java/org/gradle/testretry/internal/config/DefaultTestRetryTaskExtension.java
+++ b/plugin/src/main/java/org/gradle/testretry/internal/config/DefaultTestRetryTaskExtension.java
@@ -19,7 +19,10 @@
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.SetProperty;
+import org.gradle.api.tasks.testing.Test;
+import org.gradle.process.JavaForkOptions;
import org.gradle.testretry.TestRetryTaskExtension;
+import org.jetbrains.annotations.Nullable;
import javax.inject.Inject;
@@ -33,6 +36,8 @@ public class DefaultTestRetryTaskExtension implements TestRetryTaskExtension {
private final ClassRetryCriteria classRetryCriteria;
+ private Action super JavaForkOptions> onRetry;
+
@Inject
public DefaultTestRetryTaskExtension(ObjectFactory objects) {
this.failOnPassedAfterRetry = objects.property(Boolean.class);
@@ -79,6 +84,16 @@ public void classRetry(Action super ClassRetryCriteria> action) {
action.execute(classRetryCriteria);
}
+ @Override
+ public void onRetry(Action super JavaForkOptions> action) {
+ onRetry = action;
+ }
+
+ @Override
+ public @Nullable Action super JavaForkOptions> getOnRetry() {
+ return onRetry;
+ }
+
private static final class FilterImpl implements Filter {
private final SetProperty includeClasses;
diff --git a/plugin/src/main/java/org/gradle/testretry/internal/config/TestRetryTaskExtensionAccessor.java b/plugin/src/main/java/org/gradle/testretry/internal/config/TestRetryTaskExtensionAccessor.java
index 29e7900..05c9464 100644
--- a/plugin/src/main/java/org/gradle/testretry/internal/config/TestRetryTaskExtensionAccessor.java
+++ b/plugin/src/main/java/org/gradle/testretry/internal/config/TestRetryTaskExtensionAccessor.java
@@ -15,6 +15,10 @@
*/
package org.gradle.testretry.internal.config;
+import org.gradle.api.Action;
+import org.gradle.api.tasks.testing.Test;
+import org.gradle.process.JavaForkOptions;
+
import java.util.Set;
public interface TestRetryTaskExtensionAccessor {
@@ -41,4 +45,5 @@ public interface TestRetryTaskExtensionAccessor {
boolean getSimulateNotRetryableTest();
+ Action super JavaForkOptions> getOnRetry();
}
diff --git a/plugin/src/main/java/org/gradle/testretry/internal/config/TestRetryTaskExtensionAdapter.java b/plugin/src/main/java/org/gradle/testretry/internal/config/TestRetryTaskExtensionAdapter.java
index 3891497..5340890 100644
--- a/plugin/src/main/java/org/gradle/testretry/internal/config/TestRetryTaskExtensionAdapter.java
+++ b/plugin/src/main/java/org/gradle/testretry/internal/config/TestRetryTaskExtensionAdapter.java
@@ -15,10 +15,13 @@
*/
package org.gradle.testretry.internal.config;
+import org.gradle.api.Action;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.provider.SetProperty;
+import org.gradle.api.tasks.testing.Test;
+import org.gradle.process.JavaForkOptions;
import org.gradle.testretry.TestRetryTaskExtension;
import org.gradle.util.GradleVersion;
@@ -164,6 +167,11 @@ public boolean getSimulateNotRetryableTest() {
return simulateNotRetryableTest;
}
+ @Override
+ public Action super JavaForkOptions> getOnRetry() {
+ return extension.getOnRetry();
+ }
+
private T read(Property property, T defaultValue) {
return useConventions ? property.get() : property.getOrElse(defaultValue);
}
diff --git a/plugin/src/main/java/org/gradle/testretry/internal/executer/RetryTestExecuter.java b/plugin/src/main/java/org/gradle/testretry/internal/executer/RetryTestExecuter.java
index 9e9df90..d9a5169 100644
--- a/plugin/src/main/java/org/gradle/testretry/internal/executer/RetryTestExecuter.java
+++ b/plugin/src/main/java/org/gradle/testretry/internal/executer/RetryTestExecuter.java
@@ -15,6 +15,7 @@
*/
package org.gradle.testretry.internal.executer;
+import org.gradle.api.Action;
import org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec;
import org.gradle.api.internal.tasks.testing.TestExecuter;
import org.gradle.api.internal.tasks.testing.TestFramework;
@@ -22,6 +23,7 @@
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.tasks.testing.Test;
import org.gradle.internal.reflect.Instantiator;
+import org.gradle.process.JavaForkOptions;
import org.gradle.testretry.internal.config.TestRetryTaskExtensionAccessor;
import org.gradle.testretry.internal.executer.framework.TestFrameworkStrategy;
import org.gradle.testretry.internal.filter.AnnotationInspectorImpl;
@@ -115,6 +117,12 @@ public void execute(JvmTestExecutionSpec spec, TestResultProcessor testResultPro
JvmTestExecutionSpec testExecutionSpec = spec;
while (true) {
+ if (retryCount == 1) {
+ Action super JavaForkOptions> onRetry = extension.getOnRetry();
+ if (onRetry != null) {
+ onRetry.execute(testExecutionSpec.getJavaForkOptions());
+ }
+ }
delegate.execute(testExecutionSpec, retryTestResultProcessor);
RoundResult result = retryTestResultProcessor.getResult();
lastResult = result;