Skip to content

Commit ca0c86b

Browse files
committed
Migrate outdated APIs and bump the min Gradle requirement to 7.1
1 parent a425d0d commit ca0c86b

File tree

4 files changed

+10
-30
lines changed

4 files changed

+10
-30
lines changed

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,11 +18,8 @@
1818
import javax.inject.Inject;
1919

2020
import org.gradle.api.GradleException;
21-
import org.gradle.api.internal.plugins.DslObject;
2221
import org.gradle.api.plugins.GroovyBasePlugin;
2322
import org.gradle.api.tasks.GroovySourceDirectorySet;
24-
import org.gradle.api.tasks.GroovySourceSet;
25-
import org.gradle.util.GradleVersion;
2623

2724
import com.diffplug.spotless.generic.LicenseHeaderStep;
2825

@@ -66,12 +63,7 @@ protected void setupTask(SpotlessTask task) {
6663
target = getSources(getProject(),
6764
message,
6865
sourceSet -> {
69-
if (GradleVersion.current().compareTo(GradleVersion.version(SpotlessPlugin.VER_GRADLE_javaPluginExtension)) >= 0) {
70-
return sourceSet.getExtensions().getByType(GroovySourceDirectorySet.class);
71-
} else {
72-
final GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class);
73-
return groovySourceSet.getGroovy();
74-
}
66+
return sourceSet.getExtensions().getByType(GroovySourceDirectorySet.class);
7567
},
7668
file -> {
7769
final String name = file.getName();

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 DiffPlug
2+
* Copyright 2023-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,31 +22,20 @@
2222
import org.gradle.api.Project;
2323
import org.gradle.api.file.FileCollection;
2424
import org.gradle.api.file.SourceDirectorySet;
25-
import org.gradle.api.plugins.JavaPluginConvention;
2625
import org.gradle.api.plugins.JavaPluginExtension;
2726
import org.gradle.api.specs.Spec;
2827
import org.gradle.api.tasks.SourceSet;
2928
import org.gradle.api.tasks.SourceSetContainer;
30-
import org.gradle.util.GradleVersion;
3129

3230
interface JvmLang {
3331

3432
default FileCollection getSources(Project project, String message, Function<SourceSet, SourceDirectorySet> sourceSetSourceDirectory, Spec<? super File> filterSpec) {
35-
final SourceSetContainer sourceSets;
3633
FileCollection union = project.files();
37-
if (GradleVersion.current().compareTo(GradleVersion.version(SpotlessPlugin.VER_GRADLE_javaPluginExtension)) >= 0) {
38-
final JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class);
39-
if (javaPluginExtension == null) {
40-
throw new GradleException(message);
41-
}
42-
sourceSets = javaPluginExtension.getSourceSets();
43-
} else {
44-
final JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin(JavaPluginConvention.class);
45-
if (javaPluginConvention == null) {
46-
throw new GradleException(message);
47-
}
48-
sourceSets = javaPluginConvention.getSourceSets();
34+
final JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class);
35+
if (javaPluginExtension == null) {
36+
throw new GradleException(message);
4937
}
38+
final SourceSetContainer sourceSets = javaPluginExtension.getSourceSets();
5039
for (SourceSet sourceSet : sourceSets) {
5140
union = union.plus(sourceSetSourceDirectory.apply(sourceSet).filter(filterSpec));
5241
}

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727

2828
public class SpotlessPlugin implements Plugin<Project> {
2929
static final String SPOTLESS_MODERN = "spotlessModern";
30-
static final String VER_GRADLE_min = "6.1.1";
31-
static final String VER_GRADLE_javaPluginExtension = "7.1";
30+
static final String VER_GRADLE_min = "7.1";
3231
static final String VER_GRADLE_minVersionForCustom = "8.4";
3332
private static final int MINIMUM_JRE = 11;
3433

testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -82,7 +82,7 @@ private static Provisioner createWithRepositories(Consumer<RepositoryHandler> re
8282
return config.resolve();
8383
} catch (ResolveException e) {
8484
/* Provide Maven coordinates in exception message instead of static string 'detachedConfiguration' */
85-
throw new ResolveException(config.getDescription(), e);
85+
throw Errors.asRuntime(e);
8686
} finally {
8787
// delete the temp dir
8888
try {

0 commit comments

Comments
 (0)