Skip to content

Commit 8631e87

Browse files
authored
Document and localize Maven skip properties (#3009)
2 parents 6ce0a2a + ea40f85 commit 8631e87

6 files changed

Lines changed: 86 additions & 22 deletions

File tree

plugin-maven/CHANGES.md

Lines changed: 1 addition & 0 deletions
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
- Concurrent P2 provisioning no longer races Solstice's on-disk cache (affects Eclipse-based formatters under parallel builds). ([#3004](https://github.com/diffplug/spotless/issues/3004))
88
### Changes
9+
- Document Maven skip properties `spotless.skip`, `spotless.check.skip`, and `spotless.apply.skip`. Goal-specific skips now live on their own mojos so they no longer leak across goals. ([#3009](https://github.com/diffplug/spotless/pull/3009))
910
- Bump default `adocfmt` version `0.2.0` -> `0.3.1`, which adds table formatting support (`<formatTables>`, `<tableLayout>`, `<tableMaxLineWidth>`, `<tableBlankLines>`).
1011
- Add support to apply alternate license header within same format ([#872](https://github.com/diffplug/spotless/issues/872))
1112
- Add support to skip license header application based on source file content pattern ([#650](https://github.com/diffplug/spotless/issues/650)).

plugin-maven/README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,12 +2104,23 @@ You can easily set the line endings of different files using [a `.gitattributes`
21042104

21052105
<a name="enforceCheck"></a>
21062106

2107-
## Disabling warnings and error messages
2107+
## Disabling Spotless goals
21082108

2109-
By default, `spotless:check` is bound to the `verify` phase. You might want to disable this behavior. We [recommend against this](https://github.com/diffplug/spotless/issues/79#issuecomment-290844602), but it's easy to do if you'd like:
2109+
By default, `spotless:check` is bound to the `verify` phase. You might want to disable Spotless for some builds. We [recommend against this](https://github.com/diffplug/spotless/issues/79#issuecomment-290844602), but the following properties are available:
21102110

2111-
- set `-Dspotless.check.skip=true` at the command line
2112-
- set `spotless.check.skip` to `true` in the `<properties>` section of the `pom.xml`
2111+
| Property | Scope | Effect |
2112+
| --- | --- | --- |
2113+
| `spotless.skip` | `spotless:check` and `spotless:apply` | Skips both formatting goals |
2114+
| `spotless.check.skip` | `spotless:check` only | Skips only the check goal |
2115+
| `spotless.apply.skip` | `spotless:apply` only | Skips only the apply goal |
2116+
2117+
You can set them at the command line or in the `<properties>` section of the `pom.xml`:
2118+
2119+
- `-Dspotless.skip=true` / `<spotless.skip>true</spotless.skip>` — skip both `spotless:check` and `spotless:apply`
2120+
- `-Dspotless.check.skip=true` / `<spotless.check.skip>true</spotless.check.skip>` — skip only `spotless:check` (including when it is bound to `verify`)
2121+
- `-Dspotless.apply.skip=true` / `<spotless.apply.skip>true</spotless.apply.skip>` — skip only `spotless:apply`
2122+
2123+
`spotless.check.skip` does **not** skip `spotless:apply`, and `spotless.apply.skip` does **not** skip `spotless:check`. Use `spotless.skip` when you want both. These properties do **not** affect `spotless:install-git-pre-push-hook`.
21132124

21142125
### Suppressing lint errors
21152126

plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo {
120120
@Parameter(property = "spotless.skip", defaultValue = "false")
121121
private boolean skip;
122122

123-
@Parameter(property = "spotless.apply.skip", defaultValue = "false")
124-
private boolean applySkip;
125-
126-
@Parameter(property = "spotless.check.skip", defaultValue = "false")
127-
private boolean checkSkip;
128-
129123
@Parameter(defaultValue = "${project}", required = true, readonly = true)
130124
private MavenProject project;
131125

@@ -305,16 +299,14 @@ private boolean shouldSkip() {
305299
getLog().debug("Skipping for incremental builds as parameter 'enableForIncrementalBuilds' is set to 'false'");
306300
return true;
307301
}
302+
return isGoalSpecificSkip();
303+
}
308304

309-
switch (goal) {
310-
case GOAL_CHECK:
311-
return checkSkip;
312-
case GOAL_APPLY:
313-
return applySkip;
314-
default:
315-
break;
316-
}
317-
305+
/**
306+
* Goal-specific skip flags live on the concrete mojos (e.g. {@code spotless.check.skip}).
307+
* Override when a goal has its own property.
308+
*/
309+
protected boolean isGoalSpecificSkip() {
318310
return false;
319311
}
320312

plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public class SpotlessApplyMojo extends AbstractSpotlessMojo {
4747
@Parameter(property = "spotlessIdeHookUseStdOut")
4848
private boolean spotlessIdeHookUseStdOut;
4949

50+
@Parameter(property = "spotless.apply.skip", defaultValue = "false")
51+
private boolean applySkip;
52+
53+
@Override
54+
protected boolean isGoalSpecificSkip() {
55+
return applySkip;
56+
}
57+
5058
@Override
5159
protected void process(String name, Iterable<File> files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException {
5260
if (isIdeHook()) {

plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessCheckMojo.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2025 DiffPlug
2+
* Copyright 2016-2026 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.
@@ -41,6 +41,9 @@ public class SpotlessCheckMojo extends AbstractSpotlessMojo {
4141

4242
private static final String INCREMENTAL_MESSAGE_PREFIX = "Spotless Violation: ";
4343

44+
@Parameter(property = "spotless.check.skip", defaultValue = "false")
45+
private boolean checkSkip;
46+
4447
public enum MessageSeverity {
4548
WARNING(BuildContext.SEVERITY_WARNING), ERROR(BuildContext.SEVERITY_ERROR);
4649

@@ -63,6 +66,11 @@ public int getSeverity() {
6366
@Parameter(defaultValue = "WARNING")
6467
private MessageSeverity m2eIncrementalBuildMessageSeverity;
6568

69+
@Override
70+
protected boolean isGoalSpecificSkip() {
71+
return checkSkip;
72+
}
73+
6674
@Override
6775
protected void process(String name, Iterable<File> files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException {
6876
ImpactedFilesTracker counter = new ImpactedFilesTracker();

plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2026 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.
@@ -27,6 +27,7 @@ class SpotlessCheckMojoTest extends MavenIntegrationHarness {
2727

2828
private static final String UNFORMATTED_FILE = "license/MissingLicense.test";
2929
private static final String FORMATTED_FILE = "license/HasLicense.test";
30+
private static final String TARGET_JAVA = "src/main/java/com.github.youribonnaffe.gradle.format/Java8Test.java";
3031

3132
@Test
3233
void testSpotlessCheckWithFormattingViolations() throws Exception {
@@ -46,6 +47,19 @@ void testSkipSpotlessCheckWithFormattingViolations() throws Exception {
4647
testSpotlessCheck(UNFORMATTED_FILE, "spotless:check -Dspotless.check.skip", false);
4748
}
4849

50+
@Test
51+
void testSkipAllGoalsWithSpotlessSkip() throws Exception {
52+
writePomWithJavaLicenseHeaderStep();
53+
testSpotlessCheck(UNFORMATTED_FILE, "spotless:check -Dspotless.skip", false);
54+
}
55+
56+
@Test
57+
void testApplySkipDoesNotSkipCheck() throws Exception {
58+
writePomWithJavaLicenseHeaderStep();
59+
// apply.skip must not suppress check
60+
testSpotlessCheck(UNFORMATTED_FILE, "spotless:check -Dspotless.apply.skip", true);
61+
}
62+
4963
@Test
5064
void testSpotlessCheckBindingToVerifyPhase() throws Exception {
5165
writePom(
@@ -68,9 +82,39 @@ void testSpotlessCheckBindingToVerifyPhase() throws Exception {
6882
testSpotlessCheck(UNFORMATTED_FILE, "verify", true);
6983
}
7084

85+
@Test
86+
void testApplySkipLeavesFileUnformatted() throws Exception {
87+
writePomWithJavaLicenseHeaderStep();
88+
setFile("license.txt").toResource("license/TestLicense");
89+
setFile(TARGET_JAVA).toResource(UNFORMATTED_FILE);
90+
91+
mavenRunner().withArguments("spotless:apply -Dspotless.apply.skip").runNoError();
92+
assertFile(TARGET_JAVA).sameAsResource(UNFORMATTED_FILE);
93+
}
94+
95+
@Test
96+
void testSpotlessSkipLeavesApplyUnformatted() throws Exception {
97+
writePomWithJavaLicenseHeaderStep();
98+
setFile("license.txt").toResource("license/TestLicense");
99+
setFile(TARGET_JAVA).toResource(UNFORMATTED_FILE);
100+
101+
mavenRunner().withArguments("spotless:apply -Dspotless.skip").runNoError();
102+
assertFile(TARGET_JAVA).sameAsResource(UNFORMATTED_FILE);
103+
}
104+
105+
@Test
106+
void testCheckSkipDoesNotSkipApply() throws Exception {
107+
writePomWithJavaLicenseHeaderStep();
108+
setFile("license.txt").toResource("license/TestLicense");
109+
setFile(TARGET_JAVA).toResource(UNFORMATTED_FILE);
110+
111+
mavenRunner().withArguments("spotless:apply -Dspotless.check.skip").runNoError();
112+
assertFile(TARGET_JAVA).sameAsResource(FORMATTED_FILE);
113+
}
114+
71115
private void testSpotlessCheck(String fileName, String command, boolean expectError) throws Exception {
72116
setFile("license.txt").toResource("license/TestLicense");
73-
setFile("src/main/java/com.github.youribonnaffe.gradle.format/Java8Test.java").toResource(fileName);
117+
setFile(TARGET_JAVA).toResource(fileName);
74118

75119
MavenRunner mavenRunner = mavenRunner().withArguments(command);
76120

0 commit comments

Comments
 (0)