Skip to content

Commit

Permalink
fix: stop depending on deprecated JavaPluginConvention
Browse files Browse the repository at this point in the history
  • Loading branch information
KengoTODA committed Nov 14, 2021
1 parent 41e7ea4 commit c160f5d
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit c160f5d

Please sign in to comment.