diff --git a/CHANGES.md b/CHANGES.md index c7f75ca609..055f94fbf2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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)) diff --git a/build.gradle.kts b/build.gradle.kts index 58c59d06ec..9896e74eb0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b2860cda20..4c8a98089d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } @@ -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" @@ -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" @@ -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" diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 942a72b1de..8994884dbe 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -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") @@ -12,6 +13,61 @@ extra["artifactId"] = property("artifactIdLib") version = spotlessChangelog.versionNext +val Provider.version: Provider + 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) diff --git a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java index 31ed946244..2c8a7a0d65 100644 --- a/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java @@ -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. @@ -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; @@ -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() { diff --git a/lib/src/main/java/com/diffplug/spotless/asciidoc/AdocfmtStep.java b/lib/src/main/java/com/diffplug/spotless/asciidoc/AdocfmtStep.java index 69a8b6bd30..a2de0ad50f 100644 --- a/lib/src/main/java/com/diffplug/spotless/asciidoc/AdocfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/asciidoc/AdocfmtStep.java @@ -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:"; @@ -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() { diff --git a/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsStep.java b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsStep.java index 39049fa20e..859671adba 100644 --- a/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsStep.java @@ -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. @@ -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; @@ -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, diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index 5f181d029c..756db6c405 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -49,7 +49,7 @@ public final class CleanthatJavaStep implements Serializable { /** * CleanThat changelog is available at here. */ - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(17, "2.25"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(17, BuildConfig.VERSION_CLEANTHAT); private final JarState.Promised jarState; private final String version; diff --git a/lib/src/main/java/com/diffplug/spotless/java/ExpandWildcardImportsStep.java b/lib/src/main/java/com/diffplug/spotless/java/ExpandWildcardImportsStep.java index ef1b3fd467..2ee089c751 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ExpandWildcardImportsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ExpandWildcardImportsStep.java @@ -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 typeSolverClasspath; private final JarState.Promised jarState; diff --git a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java index ff40fc0d6d..079955a731 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java @@ -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; diff --git a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java index f51e0356d0..5840cd4073 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java @@ -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. @@ -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; diff --git a/lib/src/main/java/com/diffplug/spotless/java/PrinceOfSpaceStep.java b/lib/src/main/java/com/diffplug/spotless/java/PrinceOfSpaceStep.java index f007a1dd52..d7d519efb3 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/PrinceOfSpaceStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/PrinceOfSpaceStep.java @@ -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; diff --git a/lib/src/main/java/com/diffplug/spotless/java/ShortenFullyQualifiedTypesStep.java b/lib/src/main/java/com/diffplug/spotless/java/ShortenFullyQualifiedTypesStep.java index a24e200b66..1c247b218a 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ShortenFullyQualifiedTypesStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ShortenFullyQualifiedTypesStep.java @@ -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; diff --git a/lib/src/main/java/com/diffplug/spotless/java/TableTestFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/java/TableTestFormatterStep.java index 3b8cc46f38..e4e19bdaab 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/TableTestFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/TableTestFormatterStep.java @@ -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"; @@ -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() { diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java index 3b8ef48026..deb37b0bb6 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java @@ -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. @@ -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; @@ -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) { diff --git a/lib/src/main/java/com/diffplug/spotless/json/JsonPatchStep.java b/lib/src/main/java/com/diffplug/spotless/json/JsonPatchStep.java index dce0c3a307..4d293d86a8 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JsonPatchStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JsonPatchStep.java @@ -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. @@ -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; @@ -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) { @@ -64,7 +67,7 @@ public static FormatterStep create(String zjsonPatchVersion, String patchString, } public static FormatterStep create(List> patch, Provisioner provisioner) { - return create(DEFAULT_VERSION, patch, provisioner); + return create(JsonBuildConfig.VERSION_ZJSONPATCH, patch, provisioner); } public static FormatterStep create(String zjsonPatchVersion, List> patch, Provisioner provisioner) { diff --git a/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java b/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java index 3fbe8ae7b9..70920d7553 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java @@ -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. @@ -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; @@ -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); } diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 5ad4034bb6..b7e14f749f 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -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. @@ -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; diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index 8efe5a61b7..a63c9bc4d5 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -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. @@ -49,13 +49,12 @@ private DiktatStep(JarState.Promised jarState, String versionDiktat, boolean isS private static final String PACKAGE_RELOCATED_VERSION = "2.0.0"; - private static final String DEFAULT_VERSION = "2.0.0"; private static final String NAME = "diktat"; private static final String MAVEN_COORDINATE_PRE_2_0_0 = "org.cqfn.diktat:diktat-rules:"; private static final String MAVEN_COORDINATE = "com.saveourtool.diktat:diktat-runner:"; public static String defaultVersionDiktat() { - return DEFAULT_VERSION; + return KotlinBuildConfig.VERSION_DIKTAT; } public static FormatterStep create(Provisioner provisioner) { diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 1da50be59e..558b20e1e7 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -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. @@ -38,7 +38,7 @@ public final class KtLintStep implements Serializable { @Serial private static final long serialVersionUID = 1L; - private static final String DEFAULT_VERSION = "1.8.0"; + private static final String NAME = "ktlint"; private static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; private static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; @@ -83,7 +83,7 @@ public static FormatterStep create(String version, } public static String defaultVersion() { - return DEFAULT_VERSION; + return KotlinBuildConfig.VERSION_KTLINT; } private State equalityState() { diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java index 689332d2a7..1984b58097 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -41,7 +41,7 @@ public final class KtfmtStep implements Serializable { @Serial private static final long serialVersionUID = 1L; - private static final String DEFAULT_VERSION = "0.63"; + private static final String NAME = "ktfmt"; private static final String MAVEN_COORDINATE = "com.facebook:ktfmt:"; @@ -219,7 +219,7 @@ public static FormatterStep create(String version, Provisioner provisioner, @Nul } public static String defaultVersion() { - return DEFAULT_VERSION; + return KotlinBuildConfig.VERSION_KTFMT; } private State equalityState() { @@ -495,15 +495,14 @@ private Class getTrailingCommaManagementStrategyClazz() throws Exception { } private @Nullable Boolean getManageTrailingCommasFrom( - @Nullable TrailingCommaManagementStrategy trailingCommaManagementStrategy - ) { + @Nullable TrailingCommaManagementStrategy trailingCommaManagementStrategy) { if (trailingCommaManagementStrategy == null) { return null; } return switch (trailingCommaManagementStrategy) { - case NONE, ONLY_ADD -> false; - case COMPLETE -> true; + case NONE, ONLY_ADD -> false; + case COMPLETE -> true; }; } } diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java index 82848e08ef..24c8db8299 100644 --- a/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java @@ -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. @@ -29,7 +29,6 @@ public final class FlexmarkStep implements Serializable { @Serial private static final long serialVersionUID = 1L; - private static final String DEFAULT_VERSION = "0.64.8"; private static final String MAVEN_COORDINATE = "com.vladsch.flexmark:flexmark-all:"; public static final String NAME = "flexmark-java"; @@ -57,7 +56,7 @@ public static FormatterStep create(String version, Provisioner provisioner, Flex } public static String defaultVersion() { - return DEFAULT_VERSION; + return MarkdownBuildConfig.VERSION_FLEXMARK; } private State equalityState() { diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java index b08148d8c8..bde620c172 100644 --- a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java @@ -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. @@ -42,7 +42,6 @@ public final class FreshMarkStep implements Serializable { @Serial private static final long serialVersionUID = 1L; - private static final String DEFAULT_VERSION = "1.3.1"; private static final String NAME = "freshmark"; private static final String MAVEN_COORDINATE = "com.diffplug.freshmark:freshmark:"; @@ -85,7 +84,7 @@ public static FormatterStep create(String version, Map properties, Pr } public static String defaultVersion() { - return DEFAULT_VERSION; + return MarkdownBuildConfig.VERSION_FRESHMARK; } private State equalityState() throws Exception { diff --git a/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java b/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java index 9825cfa4d8..5054ed2238 100644 --- a/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java +++ b/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java @@ -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. @@ -23,7 +23,7 @@ public class SortPomCfg implements Serializable { @Serial private static final long serialVersionUID = 1L; - public String version = "4.0.0"; + public String version = PomBuildConfig.VERSION_SORTPOM; public String encoding = "UTF-8"; diff --git a/lib/src/main/java/com/diffplug/spotless/rdf/RdfFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/rdf/RdfFormatterStep.java index 8a1cd44922..4a538b19ec 100644 --- a/lib/src/main/java/com/diffplug/spotless/rdf/RdfFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/rdf/RdfFormatterStep.java @@ -28,12 +28,12 @@ import com.diffplug.spotless.Provisioner; public class RdfFormatterStep implements Serializable { - public static final String LATEST_TURTLE_FORMATTER_VERSION = "2.0.1"; + public static final String LATEST_TURTLE_FORMATTER_VERSION = RdfBuildConfig.VERSION_COOL_RDF_FORMATTER; @Serial private static final long serialVersionUID = 1L; private static final Jvm.Support JVM_SUPPORT = Jvm. support("cool-rdf-formatter") - .add(25, "2.0.1"); + .add(25, RdfBuildConfig.VERSION_COOL_RDF_FORMATTER); private static final String TURTLE_FORMATTER_COORDINATES = "cool.rdf:cool-rdf-formatter"; diff --git a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java index 9e045b41d6..b04d0f2cc4 100644 --- a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java @@ -38,7 +38,7 @@ public final class ScalaFmtStep implements Serializable { @Serial private static final long serialVersionUID = 1L; - static final String DEFAULT_VERSION = "3.8.1"; + static final String DEFAULT_VERSION = ScalaBuildConfig.VERSION_SCALAFMT; private static final String DEFAULT_SCALA_MAJOR_VERSION = "2.13"; private static final String NAME = "scalafmt"; diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java index 36b10fa061..1f3cfae576 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java @@ -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. @@ -35,7 +35,6 @@ public final class JacksonYamlStep implements Serializable { @Serial private static final long serialVersionUID = 1L; private static final String MAVEN_COORDINATE = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:"; - private static final String DEFAULT_VERSION = "2.14.1"; public static final String NAME = "jacksonYaml"; private final JarState.Promised jarState; @@ -47,7 +46,7 @@ private JacksonYamlStep(JarState.Promised jarState, JacksonYamlConfig jacksonCon } public static String defaultVersion() { - return DEFAULT_VERSION; + return YamlBuildConfig.VERSION_JACKSON; } public static FormatterStep create(JacksonYamlConfig jacksonConfig, diff --git a/lib/src/test/java/com/diffplug/spotless/pom/SortPomCfgTest.java b/lib/src/test/java/com/diffplug/spotless/pom/SortPomCfgTest.java index b0a336f189..aad1af2770 100644 --- a/lib/src/test/java/com/diffplug/spotless/pom/SortPomCfgTest.java +++ b/lib/src/test/java/com/diffplug/spotless/pom/SortPomCfgTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2025 DiffPlug + * Copyright 2025-2026 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ void testDefaultValues() { SortPomCfg cfg = new SortPomCfg(); // Test default values using AssertJ - assertThat(cfg.version).isEqualTo("4.0.0"); + assertThat(cfg.version).isEqualTo(PomBuildConfig.VERSION_SORTPOM); assertThat(cfg.encoding).isEqualTo("UTF-8"); assertThat(cfg.lineSeparator).isEqualTo(System.getProperty("line.separator")); assertThat(cfg.expandEmptyElements).isFalse(); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7bc475f509..ab13aeaba0 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [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 - `versionCatalog()` 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)) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 0432614091..9ddfb89eb0 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -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. @@ -29,7 +29,6 @@ public class JsonExtension extends FormatExtension { private static final int DEFAULT_INDENTATION = 4; - private static final String DEFAULT_ZJSONPATCH_VERSION = "0.4.14"; static final String NAME = "json"; @Inject @@ -216,7 +215,7 @@ public class JsonPatchConfig { private List> patch; public JsonPatchConfig(List> patch) { - this(DEFAULT_ZJSONPATCH_VERSION, patch); + this(JsonPatchStep.defaultVersion(), patch); } public JsonPatchConfig(String zjsonPatchVersion, List> patch) { diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 528c37f491..57ea3d6bd2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [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 - `` 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)) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JsonPatch.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JsonPatch.java index a822ad09e2..467f5faf84 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JsonPatch.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JsonPatch.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 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. @@ -26,10 +26,8 @@ * A {@link FormatterStepFactory} implementation that corresponds to {@code ...} configuration element. */ public class JsonPatch implements FormatterStepFactory { - private static final String DEFAULT_ZJSONPATCH_VERSION = "0.4.14"; - @Parameter - String zjsonPatchVersion = DEFAULT_ZJSONPATCH_VERSION; + String zjsonPatchVersion = JsonPatchStep.defaultVersion(); @Parameter String patch; diff --git a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java index a0111ff347..2f37e53326 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java @@ -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. @@ -52,7 +52,7 @@ void behavior() throws Exception { @Test void formatJavadoc() throws Exception { - FormatterStep step = PalantirJavaFormatStep.create("2.57.0", "PALANTIR", true, TestProvisioner.mavenCentral()); + FormatterStep step = PalantirJavaFormatStep.create(PalantirJavaFormatStep.defaultVersion(), "PALANTIR", true, TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("java/palantirjavaformat/JavaCodeWithJavaDocUnformatted.test", "java/palantirjavaformat/JavaCodeWithJavaDocFormatted.test") .testResource("java/palantirjavaformat/JavaCodeWithPackageUnformatted.test", "java/palantirjavaformat/JavaCodeWithPackageFormatted.test"); diff --git a/testlib/src/test/java/com/diffplug/spotless/java/TableTestFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/TableTestFormatterStepTest.java index f278a1d8a9..4e15af85cf 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/TableTestFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/TableTestFormatterStepTest.java @@ -25,7 +25,7 @@ class TableTestFormatterStepTest extends ResourceHarness { - private static final String VERSION = "1.1.2"; + private static final String VERSION = TableTestFormatterStep.defaultVersion(); @Test void behavior() { diff --git a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java index e04e46db7e..bb482dcf6f 100644 --- a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java @@ -36,13 +36,13 @@ void behaviorDefaultConfig() { @Test void behaviorCustomConfig() { - StepHarness.forStep(ScalaFmtStep.create(ScalaFmtStep.DEFAULT_VERSION, TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"))) + StepHarness.forStep(ScalaFmtStep.create("3.8.1", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"))) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_3.0.0"); } @Test void behaviorFileOverride() { - FormatterStep step = ScalaFmtStep.create(ScalaFmtStep.DEFAULT_VERSION, TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.fileoverride.conf")); + FormatterStep step = ScalaFmtStep.create("3.8.1", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.fileoverride.conf")); StepHarness.forStep(step) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_3.0.0"); }