From c160f5d52f7f6f171f44e500ec7e679696d5b7e2 Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Sun, 14 Nov 2021 19:49:15 +0800 Subject: [PATCH] fix: stop depending on deprecated JavaPluginConvention --- .../snom/internal/SpotBugsTaskFactory.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java b/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java index 96067c69..8d26fe88 100644 --- a/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java +++ b/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java @@ -25,8 +25,11 @@ import org.gradle.api.Project; import org.gradle.api.plugins.JavaBasePlugin; import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; +import org.gradle.api.tasks.SourceSetContainer; import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.util.GUtil; +import org.gradle.util.GradleVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,16 +41,21 @@ public void generate(Project project) { generateForAndroid(project); } + private SourceSetContainer getSourceSetContainer(Project project) { + if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) < 0) { + return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets(); + } else { + return project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets(); + } + } + private void generateForJava(Project project) { project .getPlugins() .withType(JavaBasePlugin.class) .configureEach( javaBasePlugin -> { - JavaPluginConvention convention = - project.getConvention().getPlugin(JavaPluginConvention.class); - convention - .getSourceSets() + getSourceSetContainer(project) .all( sourceSet -> { String name = sourceSet.getTaskName("spotbugs", null);