Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]

### Changes
- Generate formatter defaults from version catalog. ([#3045](https://github.com/diffplug/spotless/pull/3045))
- Bump default `gson` version `2.13.2` -> `2.14.0`. ([#3045](https://github.com/diffplug/spotless/pull/3045))
- Bump default `zjsonpatch` version `0.4.14` -> `0.4.16`. ([#3045](https://github.com/diffplug/spotless/pull/3045))
- Bump default `jackson-dataformat-yaml` version `2.14.1` -> `2.20.1`. ([#3045](https://github.com/diffplug/spotless/pull/3045))

### Fixed
- `VersionCatalogStep` preserves entries when comments contain unmatched brackets, preserves commas inside quoted strings, and keeps significant line boundaries in multiline entries. ([#3042](https://github.com/diffplug/spotless/pull/3042))
- `VersionCatalogStep` now reports unfinished entries as lints at their starting line. These fail formatting by default, so upgrading may expose catalog errors that previously caused silent data loss. ([#3042](https://github.com/diffplug/spotless/pull/3042))
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
alias(libs.plugins.buildconfig) apply false
alias(libs.plugins.equo.ide)
alias(libs.plugins.plugin.publish) apply false
alias(libs.plugins.version.compatibility) apply false
Expand Down
15 changes: 13 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ selfie = "3.1.1"
jackson = "2.20.1"
maven-api = "3.0"
ktlint = "1.8.0"
javaparser = "3.27.1"

[libraries]
durian-core = { module = "com.diffplug.durian:durian-core", version.ref = "durian" }
Expand All @@ -27,6 +28,11 @@ maven-core = { module = "org.apache.maven:maven-core", version.ref = "maven-api"
ktlint-rule-engine = { module = "com.pinterest.ktlint:ktlint-rule-engine", version.ref = "ktlint" }
ktlint-ruleset-standard = { module = "com.pinterest.ktlint:ktlint-ruleset-standard", version.ref = "ktlint" }

javaparser-core = { module = "com.github.javaparser:javaparser-core", version.ref = "javaparser" }
javaparser-symbol-solver-core = { module = "com.github.javaparser:javaparser-symbol-solver-core", version.ref = "javaparser" }

palantir-java-format-default = "com.palantir.javaformat:palantir-java-format:2.80.0"

jgit = "org.eclipse.jgit:org.eclipse.jgit:7.7.1.202607240634-r"
junit-jupiter = "org.junit.jupiter:junit-jupiter:6.1.3"
assertj-core = "org.assertj:assertj-core:3.27.7"
Expand All @@ -43,14 +49,18 @@ plexus-build-api = "org.sonatype.plexus:plexus-build-api:0.0.7"
concurrent-trees = "com.googlecode.concurrent-trees:concurrent-trees:2.6.1"
owasp-encoder = "org.owasp.encoder:encoder:1.4.0"
mustache-compiler = "com.github.spullara.mustache.java:compiler:0.9.14"
cleanthat-java = "io.github.solven-eu.cleanthat:java:2.24"
adocfmt = "org.drjekyll:adocfmt:0.3.1"
antlr4-formatter = "com.khubla.antlr4formatter:antlr4-formatter:1.2.1"
cleanthat-java = "io.github.solven-eu.cleanthat:java:2.25"
cool-rdf-formatter = "cool.rdf:cool-rdf-formatter:2.0.1"
diktat-rules = "org.cqfn.diktat:diktat-rules:1.2.5"
diktat-runner = "com.saveourtool.diktat:diktat-runner:2.0.0"
flexmark-all = "com.vladsch.flexmark:flexmark-all:0.64.8"
freshmark = "com.diffplug.freshmark:freshmark:1.3.1"
gherkin-utils = "io.cucumber:gherkin-utils:10.0.0"
google-java-format = "com.google.googlejavaformat:google-java-format:1.30.0"
gson = "com.google.code.gson:gson:2.14.0"
javaparser-symbol-solver-core = "com.github.javaparser:javaparser-symbol-solver-core:3.27.1"
json-simple = "org.json:json:20210307"
ktfmt = "com.facebook:ktfmt:0.63"
palantir-java-format = "com.palantir.javaformat:palantir-java-format:1.1.0"
prince-of-space-core = "io.github.agustafson.princeofspace:prince-of-space-core:2.2.0"
Expand All @@ -66,6 +76,7 @@ rewrite-recipe-third-party = "org.openrewrite.recipe:rewrite-third-party:0.40.1"
errorprone-core = "com.google.errorprone:error_prone_core:2.42.0"

[plugins]
buildconfig = "com.github.gmazzo.buildconfig:6.0.10"
test-logger = "com.adarshr.test-logger:4.0.0"
spotless = "com.diffplug.spotless:8.10.0"
spotless-changelog = "com.diffplug.spotless-changelog:3.1.2"
Expand Down
56 changes: 56 additions & 0 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import com.github.spotbugs.snom.Confidence

plugins {
`java-library`
alias(libs.plugins.buildconfig)
alias(libs.plugins.version.compatibility)
id("spotless.java-setup")
id("spotless.java-publish")
Expand All @@ -12,6 +13,61 @@ extra["artifactId"] = property("artifactIdLib")

version = spotlessChangelog.versionNext

val Provider<MinimalExternalModuleDependency>.version: Provider<String>
get() = map { it.version }

buildConfig {
packageName("com.diffplug.spotless.java")
useJavaOutput {
defaultVisibility = true
}
buildConfigField("VERSION_CLEANTHAT", libs.cleanthat.java.version)
buildConfigField("VERSION_GJF", libs.google.java.format.version)
buildConfigField("VERSION_JAVAPARSER", libs.javaparser.symbol.solver.core.version)
buildConfigField("VERSION_PALANTIR_JAVA_FORMAT", libs.palantir.java.format.default.version)
buildConfigField("VERSION_PRINCE_OF_SPACE", libs.prince.of.space.core.version)
buildConfigField("VERSION_TABLETEST_FORMATTER", libs.tabletest.formatter.core.version)

forClass("com.diffplug.spotless.antlr4", "Antlr4BuildConfig") {
buildConfigField("VERSION_ANTLR4", libs.antlr4.formatter.version)
}
forClass("com.diffplug.spotless.asciidoc", "AsciidocBuildConfig") {
buildConfigField("VERSION_ADOCFMT", libs.adocfmt.version)
}
forClass("com.diffplug.spotless.gherkin", "GherkinBuildConfig") {
buildConfigField("VERSION_GHERKIN_UTILS", libs.gherkin.utils.version)
}
forClass("com.diffplug.spotless.json", "JsonBuildConfig") {
buildConfigField("VERSION_JACKSON", libs.jackson.databind.version)
buildConfigField("VERSION_JSON_SIMPLE", libs.json.simple.version)
buildConfigField("VERSION_ZJSONPATCH", libs.zjsonpatch.version)
}
forClass("com.diffplug.spotless.json.gson", "GsonBuildConfig") {
buildConfigField("VERSION_GSON", libs.gson.version)
}
forClass("com.diffplug.spotless.kotlin", "KotlinBuildConfig") {
buildConfigField("VERSION_DIKTAT", libs.diktat.runner.version)
buildConfigField("VERSION_KTFMT", libs.ktfmt.version)
buildConfigField("VERSION_KTLINT", libs.ktlint.rule.engine.version)
}
forClass("com.diffplug.spotless.markdown", "MarkdownBuildConfig") {
buildConfigField("VERSION_FLEXMARK", libs.flexmark.all.version)
buildConfigField("VERSION_FRESHMARK", libs.freshmark.version)
}
forClass("com.diffplug.spotless.pom", "PomBuildConfig") {
buildConfigField("VERSION_SORTPOM", libs.sortpom.sorter.version)
}
forClass("com.diffplug.spotless.rdf", "RdfBuildConfig") {
buildConfigField("VERSION_COOL_RDF_FORMATTER", libs.cool.rdf.formatter.version)
}
forClass("com.diffplug.spotless.scala", "ScalaBuildConfig") {
buildConfigField("VERSION_SCALAFMT", libs.scalafmt.core.version)
}
forClass("com.diffplug.spotless.yaml", "YamlBuildConfig") {
buildConfigField("VERSION_JACKSON", libs.jackson.dataformat.yaml.version)
}
}

val needsGlue =
listOf(
// (alphabetic order please)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2025 DiffPlug
* Copyright 2016-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,6 @@ public final class Antlr4FormatterStep implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private static final String MAVEN_COORDINATE = "com.khubla.antlr4formatter:antlr4-formatter:";
private static final String DEFAULT_VERSION = "1.2.1";
public static final String NAME = "antlr4Formatter";

private final JarState.Promised jarState;
Expand All @@ -51,7 +50,7 @@ public static FormatterStep create(String version, Provisioner provisioner) {
}

public static String defaultVersion() {
return DEFAULT_VERSION;
return Antlr4BuildConfig.VERSION_ANTLR4;
}

private State equalityState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
public final class AdocfmtStep implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private static final String DEFAULT_VERSION = "0.3.1";
private static final String NAME = "adocfmt";
private static final String MAVEN_COORDINATE = "org.drjekyll:adocfmt:";

Expand Down Expand Up @@ -64,7 +63,7 @@ public static FormatterStep create(String version, Provisioner provisioner, Adoc
}

public static String defaultVersion() {
return DEFAULT_VERSION;
return AsciidocBuildConfig.VERSION_ADOCFMT;
}

private State equalityState() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2025 DiffPlug
* Copyright 2021-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,6 @@ public final class GherkinUtilsStep implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private static final String MAVEN_COORDINATE = "io.cucumber:gherkin-utils:";
private static final String DEFAULT_VERSION = "10.0.0";
public static final String NAME = "gherkinUtils";

private final JarState.Promised jarState;
Expand All @@ -42,7 +41,7 @@ private GherkinUtilsStep(JarState.Promised jarState, GherkinUtilsConfig gherkinS
}

public static String defaultVersion() {
return DEFAULT_VERSION;
return GherkinBuildConfig.VERSION_GHERKIN_UTILS;
}

public static FormatterStep create(GherkinUtilsConfig gherkinSimpleConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class CleanthatJavaStep implements Serializable {
/**
* CleanThat changelog is available at <a href="https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD">here</a>.
*/
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(17, "2.25");
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(17, BuildConfig.VERSION_CLEANTHAT);

private final JarState.Promised jarState;
private final String version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class ExpandWildcardImportsStep implements Serializable {
private static final long serialVersionUID = 1L;

private static final String INCOMPATIBLE_ERROR_MESSAGE = "There was a problem interacting with Java-Parser; maybe you set an incompatible version?";
private static final String MAVEN_COORDINATES = "com.github.javaparser:javaparser-symbol-solver-core:3.27.1";
private static final String MAVEN_COORDINATES = "com.github.javaparser:javaparser-symbol-solver-core:" + BuildConfig.VERSION_JAVAPARSER;

private final Collection<File> typeSolverClasspath;
private final JarState.Promised jarState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static FormatterStep createInternally(String name, String groupArtifact,
.addMin(21, "1.17.0") // java 21 requires at least 1.17.0 due to https://github.com/google/google-java-format/issues/898
.addMin(25, "1.30.0") // import module (JEP 511) requires google-java-format >= 1.30.0 (https://github.com/google/google-java-format/issues/1213)
.add(17, "1.28.0") // last version compatible with JDK 17 (1.30.0 references JCAnyPattern, JDK 21+ only)
.add(21, "1.30.0"); // default on JVM 21+ (1.30.0+ handles `import module` in RemoveUnusedImports on JVM 25+)
.add(21, BuildConfig.VERSION_GJF); // default on JVM 21+ (1.30.0+ handles `import module` in RemoveUnusedImports on JVM 25+)

public static String defaultGroupArtifact() {
return MAVEN_COORDINATE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2025 DiffPlug
* Copyright 2016-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,7 +34,7 @@ public final class PalantirJavaFormatStep implements Serializable {
private static final String DEFAULT_STYLE = "PALANTIR";
private static final String NAME = "palantir-java-format";
public static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:";
public static final String DEFAULT_VERSION = "2.80.0"; // compatible with Java 11+
public static final String DEFAULT_VERSION = BuildConfig.VERSION_PALANTIR_JAVA_FORMAT; // compatible with Java 11+

/** The jar that contains the formatter. */
private final JarState.Promised jarState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class PrinceOfSpaceStep implements Serializable {
private static final long serialVersionUID = 1L;
private static final String NAME = "prince-of-space";
public static final String MAVEN_COORDINATE = "io.github.agustafson.princeofspace:prince-of-space-core:";
public static final String DEFAULT_VERSION = "2.2.0";
public static final String DEFAULT_VERSION = BuildConfig.VERSION_PRINCE_OF_SPACE;

/** The jar that contains the formatter. */
private final JarState.Promised jarState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class ShortenFullyQualifiedTypesStep implements Serializable {

private static final String NAME = "shortenFullyQualifiedTypes";
private static final String INCOMPATIBLE_ERROR_MESSAGE = "There was a problem interacting with JavaParser; maybe you set an incompatible version?";
private static final String MAVEN_COORDINATES = "com.github.javaparser:javaparser-core:3.27.1";
private static final String MAVEN_COORDINATES = "com.github.javaparser:javaparser-core:" + BuildConfig.VERSION_JAVAPARSER;

private final JarState.Promised jarState;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public final class TableTestFormatterStep implements Serializable {
private static final long serialVersionUID = 2L;
private static final String NAME = "tableTestFormatter";
private static final String MAVEN_COORDINATE = "org.tabletest:tabletest-formatter-core:";
private static final String DEFAULT_VERSION = "1.1.2";

/** Default fallback indent style ({@code "space"}) for Java/Kotlin files. */
public static final String DEFAULT_INDENT_STYLE = "space";
Expand Down Expand Up @@ -89,7 +88,7 @@ public static FormatterStep create(String version, Provisioner provisioner, Stri

/** Get default formatter version. */
public static String defaultVersion() {
return DEFAULT_VERSION;
return BuildConfig.VERSION_TABLETEST_FORMATTER;
}

private State equalityState() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2025 DiffPlug
* Copyright 2021-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,7 +34,6 @@ public final class JacksonJsonStep implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private static final String MAVEN_COORDINATE = "com.fasterxml.jackson.core:jackson-databind:";
private static final String DEFAULT_VERSION = "2.20.1";
public static final String NAME = "jacksonJson";

private final JarState.Promised jarState;
Expand All @@ -46,7 +45,7 @@ private JacksonJsonStep(JarState.Promised jarState, JacksonConfig jacksonConfig)
}

public static String defaultVersion() {
return DEFAULT_VERSION;
return JsonBuildConfig.VERSION_JACKSON;
}

public static FormatterStep create(Provisioner provisioner) {
Expand Down
11 changes: 7 additions & 4 deletions lib/src/main/java/com/diffplug/spotless/json/JsonPatchStep.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2025 DiffPlug
* Copyright 2023-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,7 +34,6 @@ public final class JsonPatchStep implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private static final String MAVEN_COORDINATE = "com.flipkart.zjsonpatch:zjsonpatch";
private static final String DEFAULT_VERSION = "0.4.16";
public static final String NAME = "apply-json-patch";

private final JarState.Promised jarState;
Expand All @@ -49,8 +48,12 @@ private JsonPatchStep(JarState.Promised jarState,
this.patch = patch;
}

public static String defaultVersion() {
return JsonBuildConfig.VERSION_ZJSONPATCH;
}

public static FormatterStep create(String patchString, Provisioner provisioner) {
return create(DEFAULT_VERSION, patchString, provisioner);
return create(JsonBuildConfig.VERSION_ZJSONPATCH, patchString, provisioner);
}

public static FormatterStep create(String zjsonPatchVersion, String patchString, Provisioner provisioner) {
Expand All @@ -64,7 +67,7 @@ public static FormatterStep create(String zjsonPatchVersion, String patchString,
}

public static FormatterStep create(List<Map<String, Object>> patch, Provisioner provisioner) {
return create(DEFAULT_VERSION, patch, provisioner);
return create(JsonBuildConfig.VERSION_ZJSONPATCH, patch, provisioner);
}

public static FormatterStep create(String zjsonPatchVersion, List<Map<String, Object>> patch, Provisioner provisioner) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2025 DiffPlug
* Copyright 2021-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,7 +34,6 @@ public final class JsonSimpleStep implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private static final String MAVEN_COORDINATE = "org.json:json:";
private static final String DEFAULT_VERSION = "20210307";
public static final String NAME = "jsonSimple";

private final JarState.Promised jarState;
Expand All @@ -48,11 +47,15 @@ private JsonSimpleStep(JarState.Promised jarState, int indentSpaces) {
public static FormatterStep create(int indent, Provisioner provisioner) {
Objects.requireNonNull(provisioner, "provisioner cannot be null");
return FormatterStep.create(NAME,
new JsonSimpleStep(JarState.promise(() -> JarState.from(MAVEN_COORDINATE + DEFAULT_VERSION, provisioner)), indent),
new JsonSimpleStep(JarState.promise(() -> JarState.from(MAVEN_COORDINATE + defaultVersion(), provisioner)), indent),
JsonSimpleStep::equalityState,
State::toFormatter);
}

public static String defaultVersion() {
return JsonBuildConfig.VERSION_JSON_SIMPLE;
}

private State equalityState() {
return new State(jarState.get(), indentSpaces);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2025 DiffPlug
* Copyright 2022-2026 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,7 +32,7 @@ public final class GsonStep implements Serializable {
private static final String MAVEN_COORDINATES = "com.google.code.gson:gson";
private static final String INCOMPATIBLE_ERROR_MESSAGE = "There was a problem interacting with Gson; maybe you set an incompatible version?";
public static final String NAME = "gson";
public static final String DEFAULT_VERSION = "2.13.2";
public static final String DEFAULT_VERSION = GsonBuildConfig.VERSION_GSON;

private final JarState.Promised jarState;
private final GsonConfig gsonConfig;
Expand Down
Loading
Loading