Skip to content

Commit c2449ef

Browse files
committed
Generate formatter defaults from version catalog
1 parent cd8b6e2 commit c2449ef

25 files changed

Lines changed: 94 additions & 43 deletions

File tree

‎CHANGES.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1111

1212
## [Unreleased]
1313

14+
### Changes
15+
- Bump default `gson` version `2.13.2` -> `2.14.0`. ([#3045](https://github.com/diffplug/spotless/pull/3045))
16+
1417
### Fixed
1518
- `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))
1619
- `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))

‎build.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
plugins {
2+
alias(libs.plugins.buildconfig) apply false
23
alias(libs.plugins.equo.ide)
34
alias(libs.plugins.test.logger) apply false
45
alias(libs.plugins.spotless.changelog) apply false

‎gradle/libs.versions.toml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ selfie = "3.1.1"
55
jackson = "2.20.1"
66
maven-api = "3.0"
77
ktlint = "1.8.0"
8+
palantir-java-format-default = "2.80.0"
89

910
[libraries]
1011
durian-core = { module = "com.diffplug.durian:durian-core", version.ref = "durian" }
@@ -43,7 +44,7 @@ plexus-build-api = "org.sonatype.plexus:plexus-build-api:0.0.7"
4344
concurrent-trees = "com.googlecode.concurrent-trees:concurrent-trees:2.6.1"
4445
owasp-encoder = "org.owasp.encoder:encoder:1.4.0"
4546
mustache-compiler = "com.github.spullara.mustache.java:compiler:0.9.14"
46-
cleanthat-java = "io.github.solven-eu.cleanthat:java:2.24"
47+
cleanthat-java = "io.github.solven-eu.cleanthat:java:2.25"
4748
diktat-rules = "org.cqfn.diktat:diktat-rules:1.2.5"
4849
diktat-runner = "com.saveourtool.diktat:diktat-runner:2.0.0"
4950
flexmark-all = "com.vladsch.flexmark:flexmark-all:0.64.8"
@@ -66,6 +67,7 @@ rewrite-recipe-third-party = "org.openrewrite.recipe:rewrite-third-party:0.40.1"
6667
errorprone-core = "com.google.errorprone:error_prone_core:2.42.0"
6768

6869
[plugins]
70+
buildconfig = "com.github.gmazzo.buildconfig:6.0.10"
6971
test-logger = "com.adarshr.test-logger:4.0.0"
7072
spotless = "com.diffplug.spotless:8.10.0"
7173
spotless-changelog = "com.diffplug.spotless-changelog:3.1.2"

‎lib/build.gradle‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,58 @@ import org.gradle.util.GradleVersion
22

33
plugins {
44
id 'java-library'
5+
id 'com.github.gmazzo.buildconfig'
56
id 'io.github.davidburstrom.version-compatibility'
67
}
78
ext.artifactId = project.artifactIdLib
89
version = rootProject.spotlessChangelog.versionNext
910
apply from: rootProject.file('gradle/java-setup.gradle')
1011
apply from: rootProject.file('gradle/java-publish.gradle')
1112

13+
def catalogVersion = { dependency ->
14+
dependency.map { it.versionConstraint.requiredVersion }
15+
}
16+
17+
buildConfig {
18+
packageName('com.diffplug.spotless.java')
19+
useJavaOutput {
20+
defaultVisibility = true
21+
}
22+
buildConfigField(String, 'VERSION_CLEANTHAT', catalogVersion(libs.cleanthat.java))
23+
buildConfigField(String, 'VERSION_GJF', catalogVersion(libs.google.java.format))
24+
buildConfigField(String, 'VERSION_PALANTIR_JAVA_FORMAT', libs.versions.palantir.java.format.default)
25+
buildConfigField(String, 'VERSION_PRINCE_OF_SPACE', catalogVersion(libs.prince.of.space.core))
26+
buildConfigField(String, 'VERSION_TABLETEST_FORMATTER', catalogVersion(libs.tabletest.formatter.core))
27+
28+
forClass('com.diffplug.spotless.kotlin', 'KotlinBuildConfig') {
29+
buildConfigField(String, 'VERSION_DIKTAT', catalogVersion(libs.diktat.runner))
30+
buildConfigField(String, 'VERSION_KTFMT', catalogVersion(libs.ktfmt))
31+
buildConfigField(String, 'VERSION_KTLINT', catalogVersion(libs.ktlint.rule.engine))
32+
}
33+
forClass('com.diffplug.spotless.scala', 'ScalaBuildConfig') {
34+
buildConfigField(String, 'VERSION_SCALAFMT', catalogVersion(libs.scalafmt.core))
35+
}
36+
forClass('com.diffplug.spotless.markdown', 'MarkdownBuildConfig') {
37+
buildConfigField(String, 'VERSION_FLEXMARK', catalogVersion(libs.flexmark.all))
38+
}
39+
forClass('com.diffplug.spotless.gherkin', 'GherkinBuildConfig') {
40+
buildConfigField(String, 'VERSION_GHERKIN_UTILS', catalogVersion(libs.gherkin.utils))
41+
}
42+
forClass('com.diffplug.spotless.pom', 'PomBuildConfig') {
43+
buildConfigField(String, 'VERSION_SORTPOM', catalogVersion(libs.sortpom.sorter))
44+
}
45+
forClass('com.diffplug.spotless.json', 'JsonBuildConfig') {
46+
buildConfigField(String, 'VERSION_JACKSON', catalogVersion(libs.jackson.databind))
47+
buildConfigField(String, 'VERSION_ZJSONPATCH', catalogVersion(libs.zjsonpatch))
48+
}
49+
forClass('com.diffplug.spotless.json.gson', 'GsonBuildConfig') {
50+
buildConfigField(String, 'VERSION_GSON', catalogVersion(libs.gson))
51+
}
52+
forClass('com.diffplug.spotless.yaml', 'YamlBuildConfig') {
53+
buildConfigField(String, 'VERSION_JACKSON', catalogVersion(libs.jackson.dataformat.yaml))
54+
}
55+
}
56+
1257
def NEEDS_GLUE = [
1358
// (alphabetic order please)
1459
'cleanthat',

‎lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsStep.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2025 DiffPlug
2+
* Copyright 2021-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.
@@ -30,7 +30,7 @@ public final class GherkinUtilsStep implements Serializable {
3030
@Serial
3131
private static final long serialVersionUID = 1L;
3232
private static final String MAVEN_COORDINATE = "io.cucumber:gherkin-utils:";
33-
private static final String DEFAULT_VERSION = "10.0.0";
33+
private static final String DEFAULT_VERSION = GherkinBuildConfig.VERSION_GHERKIN_UTILS;
3434
public static final String NAME = "gherkinUtils";
3535

3636
private final JarState.Promised jarState;

‎lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public final class CleanthatJavaStep implements Serializable {
4949
/**
5050
* CleanThat changelog is available at <a href="https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD">here</a>.
5151
*/
52-
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(17, "2.25");
52+
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(17, BuildConfig.VERSION_CLEANTHAT);
5353

5454
private final JarState.Promised jarState;
5555
private final String version;

‎lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private static FormatterStep createInternally(String name, String groupArtifact,
123123
.addMin(21, "1.17.0") // java 21 requires at least 1.17.0 due to https://github.com/google/google-java-format/issues/898
124124
.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)
125125
.add(17, "1.28.0") // last version compatible with JDK 17 (1.30.0 references JCAnyPattern, JDK 21+ only)
126-
.add(21, "1.30.0"); // default on JVM 21+ (1.30.0+ handles `import module` in RemoveUnusedImports on JVM 25+)
126+
.add(21, BuildConfig.VERSION_GJF); // default on JVM 21+ (1.30.0+ handles `import module` in RemoveUnusedImports on JVM 25+)
127127

128128
public static String defaultGroupArtifact() {
129129
return MAVEN_COORDINATE;

‎lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java‎

Lines changed: 2 additions & 2 deletions
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.
@@ -34,7 +34,7 @@ public final class PalantirJavaFormatStep implements Serializable {
3434
private static final String DEFAULT_STYLE = "PALANTIR";
3535
private static final String NAME = "palantir-java-format";
3636
public static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:";
37-
public static final String DEFAULT_VERSION = "2.80.0"; // compatible with Java 11+
37+
public static final String DEFAULT_VERSION = BuildConfig.VERSION_PALANTIR_JAVA_FORMAT; // compatible with Java 11+
3838

3939
/** The jar that contains the formatter. */
4040
private final JarState.Promised jarState;

‎lib/src/main/java/com/diffplug/spotless/java/PrinceOfSpaceStep.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public final class PrinceOfSpaceStep implements Serializable {
3434
private static final long serialVersionUID = 1L;
3535
private static final String NAME = "prince-of-space";
3636
public static final String MAVEN_COORDINATE = "io.github.agustafson.princeofspace:prince-of-space-core:";
37-
public static final String DEFAULT_VERSION = "2.2.0";
37+
public static final String DEFAULT_VERSION = BuildConfig.VERSION_PRINCE_OF_SPACE;
3838

3939
/** The jar that contains the formatter. */
4040
private final JarState.Promised jarState;

‎lib/src/main/java/com/diffplug/spotless/java/TableTestFormatterStep.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public final class TableTestFormatterStep implements Serializable {
3939
private static final long serialVersionUID = 2L;
4040
private static final String NAME = "tableTestFormatter";
4141
private static final String MAVEN_COORDINATE = "org.tabletest:tabletest-formatter-core:";
42-
private static final String DEFAULT_VERSION = "1.1.2";
42+
private static final String DEFAULT_VERSION = BuildConfig.VERSION_TABLETEST_FORMATTER;
4343

4444
/** Default fallback indent style ({@code "space"}) for Java/Kotlin files. */
4545
public static final String DEFAULT_INDENT_STYLE = "space";

0 commit comments

Comments
 (0)