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 e661ad80..0bfdbfa5 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 @@ -26,6 +26,8 @@ import java.util.Set; import java.util.concurrent.Callable; +import static org.gradle.testretry.internal.config.TestTaskConfigurer.supportsPropertyConventions; + public final class TestRetryTaskExtensionAdapter { // for testing only @@ -53,10 +55,6 @@ public TestRetryTaskExtensionAdapter( initialize(extension, this.useConventions); } - private static boolean supportsPropertyConventions(VersionNumber gradleVersion) { - return gradleVersion.compareTo(VersionNumber.parse("5.1")) >= 0; - } - private static void initialize(TestRetryTaskExtension extension, boolean gradle51OrLater) { if (gradle51OrLater) { extension.getMaxRetries().convention(DEFAULT_MAX_RETRIES); diff --git a/plugin/src/main/java/org/gradle/testretry/internal/config/TestTaskConfigurer.java b/plugin/src/main/java/org/gradle/testretry/internal/config/TestTaskConfigurer.java index bb57acc3..a1d2e31b 100644 --- a/plugin/src/main/java/org/gradle/testretry/internal/config/TestTaskConfigurer.java +++ b/plugin/src/main/java/org/gradle/testretry/internal/config/TestTaskConfigurer.java @@ -48,7 +48,8 @@ public static void configureTestTask(Test test, ObjectFactory objectFactory, Pro test.getInputs().property("retry.failOnPassedAfterRetry", adapter.getFailOnPassedAfterRetryInput()); - Provider isDeactivatedByTestDistributionPlugin = shouldTestRetryPluginBeDeactivated(test, objectFactory, providerFactory); + Provider isDeactivatedByTestDistributionPlugin = + shouldTestRetryPluginBeDeactivated(test, objectFactory, providerFactory, gradleVersion); test.getInputs().property("isDeactivatedByTestDistributionPlugin", isDeactivatedByTestDistributionPlugin); test.getExtensions().add(TestRetryTaskExtension.class, TestRetryTaskExtension.NAME, extension); @@ -57,13 +58,31 @@ public static void configureTestTask(Test test, ObjectFactory objectFactory, Pro test.doLast(new ConditionalTaskAction(isDeactivatedByTestDistributionPlugin, new FinalizeTaskAction())); } - private static Provider shouldTestRetryPluginBeDeactivated(Test test, ObjectFactory objectFactory, ProviderFactory providerFactory) { - Provider provider = providerFactory.provider(() -> callShouldTestRetryPluginBeDeactivated(test)); - Property result = objectFactory.property(Boolean.class).convention(provider); - result.finalizeValueOnRead(); + private static Provider shouldTestRetryPluginBeDeactivated( + Test test, + ObjectFactory objectFactory, + ProviderFactory providerFactory, + VersionNumber gradleVersion + ) { + Provider result = providerFactory.provider(() -> callShouldTestRetryPluginBeDeactivated(test)); + if (supportsPropertyConventions(gradleVersion)) { + Property property = objectFactory.property(Boolean.class).convention(result); + if (supportsFinalizeValueOnRead(gradleVersion)) { + property.finalizeValueOnRead(); + } + result = property; + } return result; } + public static boolean supportsPropertyConventions(VersionNumber gradleVersion) { + return gradleVersion.compareTo(VersionNumber.parse("5.1")) >= 0; + } + + private static boolean supportsFinalizeValueOnRead(VersionNumber gradleVersion) { + return gradleVersion.compareTo(VersionNumber.parse("6.1")) >= 0; + } + private static boolean callShouldTestRetryPluginBeDeactivated(Test test) { Object distributionExtension = test.getExtensions().findByName("distribution"); if (distributionExtension == null) { 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 36244039..406d93bd 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 @@ -29,6 +29,8 @@ import java.util.stream.Collectors; +import static org.gradle.testretry.internal.executer.framework.TestFrameworkStrategy.gradleVersionIsAtLeast; + public final class RetryTestExecuter implements TestExecuter { private final TestRetryTaskExtensionAdapter extension; @@ -121,7 +123,7 @@ public void failWithNonRetriedTestsIfAny() { } private JvmTestExecutionSpec createRetryJvmExecutionSpec(JvmTestExecutionSpec spec, TestFramework retryTestFramework) { - if (TestFrameworkStrategy.gradleVersionIsAtLeast("6.4")) { + if (gradleVersionIsAtLeast("6.4")) { // This constructor is in Gradle 6.4+ return new JvmTestExecutionSpec( retryTestFramework, diff --git a/plugin/src/main/java/org/gradle/testretry/internal/executer/framework/TestNgTestFrameworkStrategy.java b/plugin/src/main/java/org/gradle/testretry/internal/executer/framework/TestNgTestFrameworkStrategy.java index 0dd2e82c..290a8205 100644 --- a/plugin/src/main/java/org/gradle/testretry/internal/executer/framework/TestNgTestFrameworkStrategy.java +++ b/plugin/src/main/java/org/gradle/testretry/internal/executer/framework/TestNgTestFrameworkStrategy.java @@ -37,6 +37,8 @@ import java.util.Map; import java.util.Optional; +import static org.gradle.testretry.internal.executer.framework.TestFrameworkStrategy.gradleVersionIsAtLeast; + final class TestNgTestFrameworkStrategy implements TestFrameworkStrategy { private static final Logger LOGGER = LoggerFactory.getLogger(TestNgTestFrameworkStrategy.class); @@ -73,7 +75,7 @@ public TestFramework createRetrying(TestFrameworkTemplate template, TestNames fa } private TestNGTestFramework createTestFramework(TestFrameworkTemplate template, DefaultTestFilter retriedTestFilter) { - if (TestFrameworkStrategy.gradleVersionIsAtLeast("6.6")) { + if (gradleVersionIsAtLeast("6.6")) { return new TestNGTestFramework(template.task, template.task.getClasspath(), retriedTestFilter, template.objectFactory); } else { try {