From 79f60c9aa46e295f401c6ab15ad3705f5117eb70 Mon Sep 17 00:00:00 2001 From: Kashev Dalmia Date: Fri, 21 Nov 2025 18:12:46 -0600 Subject: [PATCH 1/2] Allow foreign executables to explicitly specify "use any found version" with '*' --- CHANGES.md | 2 ++ .../main/java/com/diffplug/spotless/ForeignExe.java | 3 ++- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 6 +++--- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 10 +++++----- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8079135a57..809694ab90 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +- Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757)) ## [4.1.0] - 2025-11-18 ### Changes diff --git a/lib/src/main/java/com/diffplug/spotless/ForeignExe.java b/lib/src/main/java/com/diffplug/spotless/ForeignExe.java index 8697ca68c3..f265f0eb86 100644 --- a/lib/src/main/java/com/diffplug/spotless/ForeignExe.java +++ b/lib/src/main/java/com/diffplug/spotless/ForeignExe.java @@ -36,6 +36,7 @@ public class ForeignExe implements Serializable { @Serial private static final long serialVersionUID = 1L; + private static final String VERSION_WILDCARD = "*"; private @Nullable String pathToExe; private String versionFlag = "--version"; private Pattern versionRegex = Pattern.compile("version (\\S*)"); @@ -111,7 +112,7 @@ public String confirmVersionAndGetAbsolutePath() throws IOException, Interrupted throw cantFind("Unable to parse version with /" + versionRegex + "/", cmdVersion); } String versionFound = versionMatcher.group(1); - if (!versionFound.equals(version)) { + if (!versionFound.equals(VERSION_WILDCARD) && !versionFound.equals(version)) { throw wrongVersion("You specified version " + version + ", but Spotless found " + versionFound, cmdVersion, versionFound); } return exeAbsPath; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index ff792de588..2ba9e9d91e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +- Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757)) ## [8.1.0] - 2025-11-18 ### Changes diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 2ed91844c9..fe808a043c 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -674,7 +674,7 @@ spotless { [homepage](https://github.com/psf/black). [changelog](https://github.com/psf/black/blob/master/CHANGES.md). ```gradle -black('19.10b0') // version is optional +black('19.10b0') // version is optional. Explicitly allow "any found version" with '*'. // if black is not on your path, you must specify its location manually black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') @@ -1211,7 +1211,7 @@ When formatting shell scripts via `shfmt`, configure `shfmt` settings via `.edit Refer to the `shfmt` [man page](https://github.com/mvdan/sh/blob/master/cmd/shfmt/shfmt.1.scd) for `.editorconfig` settings. ```gradle -shfmt('3.8.0') // version is optional +shfmt('3.8.0') // version is optional. Explicitly allow "any found version" with '*'. // if shfmt is not on your path, you must specify its location manually shfmt().pathToExe('/opt/homebrew/bin/shfmt') @@ -1402,7 +1402,7 @@ spotless { // you have to set the target manually target 'src/**/*.cs' - clangFormat('10.0.1') // version is optional + clangFormat('10.0.1') // version is optional. Explicitly allow "any found version" with '*'. // can also specify a code style clangFormat().style('LLVM') // or Google, Chromium, Mozilla, WebKit diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index caff25c9d3..595c963fea 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +- Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757)) ## [3.1.0] - 2025-11-18 ### Changes diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 25138c64da..1664aacdd1 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -606,7 +606,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```xml - 14.0.0-1ubuntu1.1 + 14.0.0-1ubuntu1.1 /path/to/buf @@ -635,7 +635,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```xml - 19.10b0 + 19.10b0 C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe + 3.8.0 /opt/homebrew/bin/shfmt ``` @@ -1216,7 +1216,7 @@ Standard Go formatter, part of Go distribution. ```xml - go1.25.1 + go1.25.1 /opt/sdks/go1.25.1/bin/go ``` @@ -1303,7 +1303,7 @@ RDF parsing is done via [Apache Jena](https://jena.apache.org/) in the version t [homepage](https://buf.build/) [buf repo](https://github.com/bufbuild/buf). ```xml - 1.44.0 + 1.44.0 /path/to/buf ``` From de5469f9e4f1b6d4ca21786730a912b990d42ca3 Mon Sep 17 00:00:00 2001 From: Kashev Dalmia Date: Sat, 22 Nov 2025 09:53:56 -0600 Subject: [PATCH 2/2] Run rewriteRun --- lib/src/main/java/com/diffplug/spotless/ForeignExe.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ForeignExe.java b/lib/src/main/java/com/diffplug/spotless/ForeignExe.java index f265f0eb86..861b66e8de 100644 --- a/lib/src/main/java/com/diffplug/spotless/ForeignExe.java +++ b/lib/src/main/java/com/diffplug/spotless/ForeignExe.java @@ -112,7 +112,7 @@ public String confirmVersionAndGetAbsolutePath() throws IOException, Interrupted throw cantFind("Unable to parse version with /" + versionRegex + "/", cmdVersion); } String versionFound = versionMatcher.group(1); - if (!versionFound.equals(VERSION_WILDCARD) && !versionFound.equals(version)) { + if (!VERSION_WILDCARD.equals(versionFound) && !versionFound.equals(version)) { throw wrongVersion("You specified version " + version + ", but Spotless found " + versionFound, cmdVersion, versionFound); } return exeAbsPath;