diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java index 574089eeaaa1b8..20f4d7d2ceea37 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java @@ -4,7 +4,6 @@ import java.nio.file.Path; import java.util.HashSet; import java.util.Set; -import java.util.function.Consumer; import java.util.stream.Collectors; import javax.inject.Inject; @@ -151,24 +150,9 @@ private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) { configureBuildNativeTask(project); - final Consumer configureTestTask = t -> { - // Quarkus test configuration action which should be executed before any Quarkus test - // Use anonymous classes in order to leverage task avoidance. - t.doFirst(new Action() { - @Override - public void execute(Task test) { - quarkusExt.beforeTest(t); - } - }); - // also make each task use the JUnit platform since it's the only supported test environment - t.useJUnitPlatform(); - // quarkusBuild is expected to run after the project has passed the tests - quarkusBuild.configure(task -> task.shouldRunAfter(t)); - }; - project.getPlugins().withType( BasePlugin.class, - basePlugin -> tasks.getByName(BasePlugin.ASSEMBLE_TASK_NAME).dependsOn(quarkusBuild)); + basePlugin -> tasks.named(BasePlugin.ASSEMBLE_TASK_NAME, task -> task.dependsOn(quarkusBuild))); project.getPlugins().withType( JavaPlugin.class, javaPlugin -> { @@ -287,8 +271,20 @@ public void execute(Task test) { testNative.setClasspath(nativeTestSourceSet.getRuntimeClasspath()); }); - tasks.withType(Test.class).forEach(configureTestTask); - tasks.withType(Test.class).whenTaskAdded(configureTestTask::accept); + tasks.withType(Test.class).configureEach(t -> { + // Quarkus test configuration action which should be executed before any Quarkus test + // Use anonymous classes in order to leverage task avoidance. + t.doFirst(new Action() { + @Override + public void execute(Task task) { + quarkusExt.beforeTest(t); + } + }); + // also make each task use the JUnit platform since it's the only supported test environment + t.useJUnitPlatform(); + }); + // quarkusBuild is expected to run after the project has passed the tests + quarkusBuild.configure(task -> task.shouldRunAfter(tasks.withType(Test.class))); SourceSet generatedSourceSet = sourceSets.create(QuarkusGenerateCode.QUARKUS_GENERATED_SOURCES); SourceSet generatedTestSourceSet = sourceSets.create(QuarkusGenerateCode.QUARKUS_TEST_GENERATED_SOURCES); diff --git a/devtools/gradle/gradle-extension-plugin/src/main/java/io/quarkus/extension/gradle/QuarkusExtensionPlugin.java b/devtools/gradle/gradle-extension-plugin/src/main/java/io/quarkus/extension/gradle/QuarkusExtensionPlugin.java index 6aba9d1f65eca7..f131af8caa1136 100644 --- a/devtools/gradle/gradle-extension-plugin/src/main/java/io/quarkus/extension/gradle/QuarkusExtensionPlugin.java +++ b/devtools/gradle/gradle-extension-plugin/src/main/java/io/quarkus/extension/gradle/QuarkusExtensionPlugin.java @@ -68,7 +68,7 @@ private void registerTasks(Project project, QuarkusExtensionConfiguration quarku javaPlugin -> { tasks.named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME, task -> task.finalizedBy(extensionDescriptorTask)); tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, task -> task.dependsOn(extensionDescriptorTask)); - tasks.withType(Test.class, test -> test.useJUnitPlatform()); + tasks.withType(Test.class).configureEach(Test::useJUnitPlatform); addAnnotationProcessorDependency(project); }); @@ -87,7 +87,7 @@ private void registerTasks(Project project, QuarkusExtensionConfiguration quarku task.setDeploymentModuleClasspath(deploymentModuleClasspath); }); - deploymentProject.getTasks().withType(Test.class, test -> { + deploymentProject.getTasks().withType(Test.class).configureEach(test -> { test.useJUnitPlatform(); test.doFirst(task -> { final Map props = test.getSystemProperties();