Skip to content

Commit 0f6b181

Browse files
committed
fix: depends on check task after java-base plugin is applied to project
1 parent 68bc009 commit 0f6b181

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/main/groovy/com/github/spotbugs/snom/SpotBugsPlugin.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package com.github.spotbugs.snom;
1515

1616
import com.github.spotbugs.snom.internal.SpotBugsTaskFactory;
17-
import edu.umd.cs.findbugs.annotations.Nullable;
1817
import org.gradle.api.Plugin;
1918
import org.gradle.api.Project;
2019
import org.gradle.api.Task;
@@ -33,20 +32,20 @@ public class SpotBugsPlugin implements Plugin<Project> {
3332
public void apply(Project project) {
3433
project.getPluginManager().apply(SpotBugsBasePlugin.class);
3534
SpotBugsExtension extension = project.getExtensions().findByType(SpotBugsExtension.class);
35+
project
36+
.getPluginManager()
37+
.withPlugin(
38+
"java-base",
39+
javaBase -> {
40+
log.debug(
41+
"The javaBase plugin has been applied, so making the check task depending on all of SpotBugsTask");
42+
Task check = project.getTasks().getByName("check");
43+
project.getTasks().withType(SpotBugsTask.class, check::dependsOn);
44+
});
3645
createTasks(project, extension);
3746
}
3847

3948
private void createTasks(Project project, SpotBugsExtension extension) {
40-
@Nullable Task check = project.getTasks().findByName("check");
41-
log.debug("check task {}", check == null ? "not found" : "found");
42-
new SpotBugsTaskFactory()
43-
.generate(
44-
project,
45-
task -> {
46-
if (check != null) {
47-
check.dependsOn(task);
48-
}
49-
task.init(extension);
50-
});
49+
new SpotBugsTaskFactory().generate(project, task -> task.init(extension));
5150
}
5251
}

0 commit comments

Comments
 (0)