From 0f6b181e69f92d7bfbac27d8a37f4f985ba592d5 Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Mon, 9 Mar 2020 12:31:21 +0800 Subject: [PATCH] fix: depends on check task after java-base plugin is applied to project --- .../github/spotbugs/snom/SpotBugsPlugin.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java b/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java index 59470b48..5fb335ef 100644 --- a/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java +++ b/src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java @@ -14,7 +14,6 @@ package com.github.spotbugs.snom; import com.github.spotbugs.snom.internal.SpotBugsTaskFactory; -import edu.umd.cs.findbugs.annotations.Nullable; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Task; @@ -33,20 +32,20 @@ public class SpotBugsPlugin implements Plugin { public void apply(Project project) { project.getPluginManager().apply(SpotBugsBasePlugin.class); SpotBugsExtension extension = project.getExtensions().findByType(SpotBugsExtension.class); + project + .getPluginManager() + .withPlugin( + "java-base", + javaBase -> { + log.debug( + "The javaBase plugin has been applied, so making the check task depending on all of SpotBugsTask"); + Task check = project.getTasks().getByName("check"); + project.getTasks().withType(SpotBugsTask.class, check::dependsOn); + }); createTasks(project, extension); } private void createTasks(Project project, SpotBugsExtension extension) { - @Nullable Task check = project.getTasks().findByName("check"); - log.debug("check task {}", check == null ? "not found" : "found"); - new SpotBugsTaskFactory() - .generate( - project, - task -> { - if (check != null) { - check.dependsOn(task); - } - task.init(extension); - }); + new SpotBugsTaskFactory().generate(project, task -> task.init(extension)); } }