Skip to content

Commit 8592c4b

Browse files
builtbyjulsGoooler
authored andcommitted
Generate formatter defaults from version catalog
1 parent 6063a75 commit 8592c4b

25 files changed

Lines changed: 95 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.kts‎

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.plugin.publish) apply false
45
alias(libs.plugins.version.compatibility) 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.kts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import com.github.spotbugs.snom.Confidence
22

33
plugins {
44
`java-library`
5+
alias(libs.plugins.buildconfig)
56
alias(libs.plugins.version.compatibility)
67
id("spotless.java-setup")
78
id("spotless.java-publish")
@@ -12,6 +13,51 @@ extra["artifactId"] = property("artifactIdLib")
1213

1314
version = spotlessChangelog.versionNext
1415

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

‎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)