GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: expand a directory passed to targetExclude into the files under … · diffplug/spotless@3aa82b5

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • plugin-gradle
    • CHANGES.md
    • src
      • main/java/com/diffplug/gradle/spotless
        • FormatExtension.java
      • test/java/com/diffplug/gradle/spotless
        • TargetExcludeDirectoryTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎plugin-gradle/CHANGES.md‎

Copy file name to clipboardExpand all lines: plugin-gradle/CHANGES.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
66
### Fixed
77
- `prettier()` and other npm-based steps no longer fail to start on npm 12 (`EUNKNOWNCONFIG` from `--scripts-prepend-node-path`). ([#3024](https://github.com/diffplug/spotless/issues/3024))
88
- `spotlessInternalRegisterDependencies` now writes its output under a build directory that is configured after the plugin is applied, instead of always under the default `build/`. ([#2114](https://github.com/diffplug/spotless/issues/2114))
9+
- `targetExclude` now accepts a Gradle `Directory`, `DirectoryProperty`, or `Provider<Directory>` and excludes the files under it. Previously the directory was treated as a single file, so excluding one silently did nothing. ([#2667](https://github.com/diffplug/spotless/issues/2667))
910

1011
## [8.10.0] - 2026-08-17
1112
### Added
Collapse file

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

Copy file name to clipboardExpand all lines: plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
import org.gradle.api.file.ConfigurableFileTree;
4848
import org.gradle.api.file.Directory;
4949
import org.gradle.api.file.FileCollection;
50+
import org.gradle.api.file.FileSystemLocation;
5051
import org.gradle.api.plugins.BasePlugin;
52+
import org.gradle.api.provider.Provider;
5153
import org.gradle.api.tasks.TaskProvider;
5254
import org.gradle.util.GradleVersion;
5355
import org.slf4j.Logger;
@@ -344,6 +346,9 @@ private final FileCollection parseTargetIsExclude(Object target, boolean isExclu
344346
matchedFiles.exclude(excludes);
345347
}
346348
return matchedFiles;
349+
} else if (isExclude && (target instanceof FileSystemLocation || target instanceof Provider)) {
350+
// an excluded directory means the files under it, and the tree resolves them lazily
351+
return getProject().files(target).getAsFileTree();
347352
} else {
348353
return getProject().files(target);
349354
}
Collapse file

‎plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeDirectoryTest.java‎

Copy file name to clipboard
+113Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright 2026 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.gradle.spotless;
17+
18+
import java.io.IOException;
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
class TargetExcludeDirectoryTest extends GradleIntegrationHarness {
23+
@Test
24+
void targetExcludeWithDirectory() throws IOException {
25+
setFile("build.gradle").toLines(
26+
"plugins { id 'com.diffplug.spotless' }",
27+
"spotless {",
28+
" format 'toLower', {",
29+
" target '**/*.md'",
30+
" targetExclude layout.projectDirectory.dir('generated')",
31+
" custom 'lowercase', { str -> str.toLowerCase() }",
32+
" }",
33+
"}");
34+
setFile("generated/excluded.md").toLines("A B C");
35+
setFile("generated/nested/excluded.md").toLines("A B C");
36+
setFile("manual.md").toLines("A B C");
37+
38+
gradleRunner().withArguments("spotlessApply").build();
39+
40+
assertFile("generated/excluded.md").hasLines("A B C");
41+
assertFile("generated/nested/excluded.md").hasLines("A B C");
42+
assertFile("manual.md").hasLines("a b c");
43+
}
44+
45+
@Test
46+
void targetExcludeWithDirectoryProperty() throws IOException {
47+
setFile("build.gradle").toLines(
48+
"plugins { id 'com.diffplug.spotless' }",
49+
"def excluded = objects.directoryProperty()",
50+
"excluded.set(layout.projectDirectory.dir('generated'))",
51+
"spotless {",
52+
" format 'toLower', {",
53+
" target '**/*.md'",
54+
" targetExclude excluded",
55+
" custom 'lowercase', { str -> str.toLowerCase() }",
56+
" }",
57+
"}");
58+
setFile("generated/excluded.md").toLines("A B C");
59+
setFile("manual.md").toLines("A B C");
60+
61+
gradleRunner().withArguments("spotlessApply").build();
62+
63+
assertFile("generated/excluded.md").hasLines("A B C");
64+
assertFile("manual.md").hasLines("a b c");
65+
}
66+
67+
@Test
68+
void targetExcludeWithDirectoryProvider() throws IOException {
69+
setFile("build.gradle").toLines(
70+
"plugins { id 'com.diffplug.spotless' }",
71+
"spotless {",
72+
" format 'toLower', {",
73+
" target '**/*.md'",
74+
" targetExclude providers.provider { layout.projectDirectory.dir('generated') }",
75+
" custom 'lowercase', { str -> str.toLowerCase() }",
76+
" }",
77+
"}");
78+
setFile("generated/excluded.md").toLines("A B C");
79+
setFile("manual.md").toLines("A B C");
80+
81+
gradleRunner().withArguments("spotlessApply").build();
82+
83+
assertFile("generated/excluded.md").hasLines("A B C");
84+
assertFile("manual.md").hasLines("a b c");
85+
}
86+
87+
@Test
88+
void targetExcludeWithDirectoryAndConfigurationCache() throws IOException {
89+
setFile("gradle.properties").toLines("org.gradle.configuration-cache=true");
90+
setFile("build.gradle").toLines(
91+
"plugins { id 'com.diffplug.spotless' }",
92+
"spotless {",
93+
" format 'toLower', {",
94+
" target '**/*.md'",
95+
" targetExclude layout.projectDirectory.dir('generated')",
96+
" custom 'lowercase', { str -> str.toLowerCase() }",
97+
" }",
98+
"}");
99+
setFile("generated/excluded.md").toLines("A B C");
100+
setFile("manual.md").toLines("A B C");
101+
102+
gradleRunner().withArguments("spotlessApply").build();
103+
assertFile("generated/excluded.md").hasLines("A B C");
104+
assertFile("manual.md").hasLines("a b c");
105+
106+
// the exclusion still applies on a second run with the cache enabled
107+
setFile("manual.md").toLines("D E F");
108+
gradleRunner().withArguments("spotlessApply").build();
109+
assertFile("generated/excluded.md").hasLines("A B C");
110+
assertFile("manual.md").hasLines("d e f");
111+
}
112+
113+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.