Skip to content

Commit a2a3ef2

Browse files
authored
Merge branch 'main' into gradle-property
2 parents 1443d80 + a2ce4e2 commit a2a3ef2

17 files changed

+100
-125
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1212
## [Unreleased]
1313
### Changes
1414
* Bump default `ktfmt` version to latest `0.58` -> `0.59`. ([#2681](https://github.com/diffplug/spotless/pull/2681)
15+
* Use Task Providers for task initialization. [#2719](https://github.com/diffplug/spotless/pull/2719)
16+
* **BREAKING** Bump minimum supported Gradle version from 7.3 to 8.1. [#2719](https://github.com/diffplug/spotless/pull/2719)
1517
### Fixed
1618
* palantirJavaFormat is no longer arbitrarily set to outdated versions on Java 17, latest available version is always used ([#2686](https://github.com/diffplug/spotless/pull/2686) fixes [#2685](https://github.com/diffplug/spotless/issues/2685))
1719
* Use Provider API for Gradle properties. ([#2718](https://github.com/diffplug/spotless/pull/2718)

lib-extra/build.gradle

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ spotless {
3838

3939
apply from: rootProject.file('gradle/special-tests.gradle')
4040
tasks.withType(Test).configureEach {
41-
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) {
42-
// needed for EclipseCdtFormatterStepTest
43-
jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED'
44-
}
41+
// needed for EclipseCdtFormatterStepTest
42+
jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED'
4543
}
4644

4745
def NEEDS_P2_DEPS = [
@@ -50,9 +48,6 @@ def NEEDS_P2_DEPS = [
5048
'groovy',
5149
'jdt'
5250
]
53-
if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
54-
NEEDS_P2_DEPS.remove('cdt')
55-
}
5651
for (needsP2 in NEEDS_P2_DEPS) {
5752
sourceSets.register(needsP2) {
5853
compileClasspath += sourceSets.main.output

lib/build.gradle

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,9 @@ spotbugs {
131131

132132
apply from: rootProject.file('gradle/special-tests.gradle')
133133
tasks.withType(Test).configureEach {
134-
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) {
135-
// https://docs.gradle.org/7.5/userguide/upgrading_version_7.html#removes_implicit_add_opens_for_test_workers
136-
jvmArgs "--add-opens=java.base/java.lang=ALL-UNNAMED"
137-
}
134+
jvmArgs "--add-opens=java.base/java.lang=ALL-UNNAMED"
138135

139-
if (GradleVersion.current() >= GradleVersion.version('9.0')) {
140-
// https://github.com/gradle/gradle/issues/33619
141-
failOnNoDiscoveredTests = false
142-
}
136+
failOnNoDiscoveredTests = false
143137
}
144138

145139
jar {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ public TaskProvider<SpotlessApply> createIndependentApplyTaskLazy(String taskNam
11381138
return spotless.project.getTasks().register(taskName, SpotlessApply.class,
11391139
task -> {
11401140
task.dependsOn(spotlessTask);
1141-
task.init(spotlessTask.get());
1141+
task.init(spotlessTask);
11421142
});
11431143
}
11441144

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.gradle.api.tasks.Input;
3333
import org.gradle.api.tasks.Internal;
3434
import org.gradle.api.tasks.TaskAction;
35+
import org.gradle.api.tasks.TaskProvider;
3536
import org.gradle.work.DisableCachingByDefault;
3637
import org.jetbrains.annotations.NotNull;
3738

@@ -133,10 +134,10 @@ public void visitFile(FileVisitDetails fileVisitDetails) {
133134
abstract Property<String> getProjectPath();
134135

135136
@Override
136-
void init(SpotlessTaskImpl impl) {
137+
void init(TaskProvider<SpotlessTaskImpl> impl) {
137138
super.init(impl);
138139
getProjectPath().set(getProject().getPath());
139-
getEncoding().set(impl.getEncoding());
140+
getEncoding().set(impl.map(SpotlessTask::getEncoding));
140141
getRunToFixMessage().convention(
141142
"Run '" + calculateGradleCommand() + " spotlessApply' to fix all violations.");
142143
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.gradle.api.DefaultTask;
2525
import org.gradle.api.tasks.Internal;
2626
import org.gradle.api.tasks.TaskAction;
27+
import org.gradle.api.tasks.TaskProvider;
2728
import org.gradle.api.tasks.UntrackedTask;
2829

2930
import com.diffplug.spotless.Formatter;
@@ -33,10 +34,10 @@
3334

3435
@UntrackedTask(because = "undeclared inputs/outputs")
3536
public class SpotlessDiagnoseTask extends DefaultTask {
36-
SpotlessTask source;
37+
TaskProvider<? extends SpotlessTask> source;
3738

3839
@Internal
39-
public SpotlessTask getSource() {
40+
public TaskProvider<? extends SpotlessTask> getSource() {
4041
return source;
4142
}
4243

@@ -45,10 +46,10 @@ public SpotlessTask getSource() {
4546
public void performAction() throws IOException {
4647
Path srcRoot = getProject().getProjectDir().toPath();
4748
Path diagnoseRoot = getProject().getLayout().getBuildDirectory().getAsFile().get()
48-
.toPath().resolve("spotless-diagnose-" + source.formatName());
49+
.toPath().resolve("spotless-diagnose-" + source.get().formatName());
4950
getProject().delete(diagnoseRoot.toFile());
50-
try (Formatter formatter = source.buildFormatter()) {
51-
for (File file : source.target) {
51+
try (Formatter formatter = source.get().buildFormatter()) {
52+
for (File file : source.get().target) {
5253
getLogger().debug("Running padded cell check on " + file);
5354
PaddedCell padded = PaddedCell.check(formatter, file);
5455
if (!padded.misbehaved()) {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,18 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) {
7878

7979
// create the check and apply control tasks
8080
TaskProvider<SpotlessApply> applyTask = tasks.register(taskName + APPLY, SpotlessApply.class, task -> {
81-
task.init(spotlessTask.get());
81+
task.init(spotlessTask);
8282
task.setGroup(TASK_GROUP);
8383
task.setEnabled(ideHook.path == null);
8484
task.dependsOn(spotlessTask);
8585
});
8686
rootApplyTask.configure(task -> task.dependsOn(ideHook.path == null ? applyTask : spotlessTask));
8787

8888
TaskProvider<SpotlessCheck> checkTask = tasks.register(taskName + CHECK, SpotlessCheck.class, task -> {
89-
SpotlessTaskImpl source = spotlessTask.get();
9089
task.setGroup(TASK_GROUP);
91-
task.init(source);
90+
task.init(spotlessTask);
9291
task.setEnabled(ideHook.path == null);
93-
task.dependsOn(source);
92+
task.dependsOn(spotlessTask);
9493

9594
// if the user runs both, make sure that apply happens first,
9695
task.mustRunAfter(applyTask);
@@ -99,7 +98,7 @@ protected void createFormatTasks(String name, FormatExtension formatExtension) {
9998

10099
// create the diagnose task
101100
TaskProvider<SpotlessDiagnoseTask> diagnoseTask = tasks.register(taskName + DIAGNOSE, SpotlessDiagnoseTask.class, task -> {
102-
task.source = spotlessTask.get();
101+
task.source = spotlessTask;
103102
task.setGroup(TASK_GROUP);
104103
task.mustRunAfter(BasePlugin.CLEAN_TASK_NAME);
105104
});

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

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

2828
public class SpotlessPlugin implements Plugin<Project> {
2929
static final String SPOTLESS_MODERN = "spotlessModern";
30-
static final String VER_GRADLE_MIN = "7.3";
30+
static final String VER_GRADLE_MIN = "8.1";
3131
static final String VER_GRADLE_MIN_VERSION_FOR_CUSTOM = "8.4";
3232
private static final int MINIMUM_JRE = 17;
3333

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.gradle.api.services.BuildService;
3939
import org.gradle.api.services.BuildServiceParameters;
4040
import org.gradle.api.tasks.Internal;
41+
import org.gradle.api.tasks.TaskProvider;
4142
import org.gradle.tooling.events.FinishEvent;
4243
import org.gradle.tooling.events.OperationCompletionListener;
4344

@@ -125,12 +126,12 @@ abstract static class ClientTask extends DefaultTask {
125126
@Inject
126127
protected abstract ObjectFactory getConfigCacheWorkaround();
127128

128-
void init(SpotlessTaskImpl impl) {
129-
usesServiceTolerateTestFailure(this, impl.getTaskServiceProvider());
130-
getSpotlessCleanDirectory().set(impl.getCleanDirectory());
131-
getSpotlessLintsDirectory().set(impl.getLintsDirectory());
132-
getTaskService().set(impl.getTaskService());
133-
getProjectDir().set(impl.getProjectDir());
129+
void init(TaskProvider<SpotlessTaskImpl> impl) {
130+
usesServiceTolerateTestFailure(this, impl.flatMap(SpotlessTaskImpl::getTaskServiceProvider));
131+
getSpotlessCleanDirectory().set(impl.map(SpotlessTask::getCleanDirectory));
132+
getSpotlessLintsDirectory().set(impl.map(SpotlessTask::getLintsDirectory));
133+
getTaskService().set(impl.flatMap(SpotlessTask::getTaskService));
134+
getProjectDir().set(impl.flatMap(SpotlessTask::getProjectDir));
134135
}
135136

136137
String sourceTaskPath() {

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 DiffPlug
2+
* Copyright 2020-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.
@@ -24,8 +24,7 @@ public class ConfigurationCacheTest extends GradleIntegrationHarness {
2424
@Override
2525
public GradleRunner gradleRunner() throws IOException {
2626
setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true");
27-
setFile("settings.gradle").toContent("enableFeaturePreview(\"STABLE_CONFIGURATION_CACHE\")");
28-
return super.gradleRunner().withGradleVersion(GradleVersionSupport.STABLE_CONFIGURATION_CACHE.version);
27+
return super.gradleRunner();
2928
}
3029

3130
@Test

0 commit comments

Comments
 (0)