Skip to content

Commit f5a403c

Browse files
JordonPhillipskstich
authored andcommitted
Bump Spotless to v7
This updates spotless to v7 Kotlin lambdas can't be serialized effectively by {spotless / gradle} right now so this replaces those lambdas with anonymous classes that implement `FormatterFunc`
1 parent fb9ef6d commit f5a403c

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import com.diffplug.spotless.FormatterFunc
2+
import java.io.Serializable
13
import java.util.regex.Pattern
24

35
plugins {
@@ -14,13 +16,25 @@ spotless {
1416
// Enforce a common license header on all files
1517
licenseHeaderFile("${project.rootDir}/config/spotless/license-header.txt")
1618
.onlyIfContentMatches("^((?!SKIPLICENSECHECK)[\\s\\S])*\$")
17-
indentWithSpaces()
19+
leadingTabsToSpaces()
1820
endWithNewline()
1921
eclipse().configFile("${project.rootDir}/config/spotless/formatting.xml")
22+
2023
// Fixes for some strange formatting applied by eclipse:
2124
// see: https://github.com/kamkie/demo-spring-jsf/blob/bcacb9dc90273a5f8d2569470c5bf67b171c7d62/build.gradle.kts#L159
22-
custom("Lambda fix") { it.replace("} )", "})").replace("} ,", "},") }
23-
custom("Long literal fix") { Pattern.compile("([0-9_]+) [Ll]").matcher(it).replaceAll("\$1L") }
25+
// These have to be implemented with anonymous classes this way instead of lambdas because of:
26+
// https://github.com/diffplug/spotless/issues/2387
27+
custom("Lambda fix", object : Serializable, FormatterFunc {
28+
override fun apply(input: String) : String {
29+
return input.replace("} )", "})").replace("} ,", "},")
30+
}
31+
})
32+
custom("Long literal fix", object : Serializable, FormatterFunc {
33+
override fun apply(input: String) : String {
34+
return Pattern.compile("([0-9_]+) [Ll]").matcher(input).replaceAll("\$1L")
35+
}
36+
})
37+
2438
// Static first, then everything else alphabetically
2539
removeUnusedImports()
2640
importOrder("\\#", "")
@@ -31,7 +45,7 @@ spotless {
3145
// Formatting for build.gradle.kts files
3246
kotlinGradle {
3347
ktlint()
34-
indentWithSpaces()
48+
leadingTabsToSpaces()
3549
trimTrailingWhitespace()
3650
endWithNewline()
3751
licenseHeaderFile(

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ junit5 = "5.11.3"
33
hamcrest = "3.0"
44
jmh = "0.6.6"
55
spotbugs = "6.0.22"
6-
spotless = "6.25.0"
6+
spotless = "7.0.2"
77
smithy-gradle = "1.1.0"
88
assertj = "3.26.3"
99
prettier4j = "0.1.1"

smithy-cli/build.gradle.kts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,15 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
8888
// This is needed in order for integration tests to find the CLI runtime image
8989
val smithyBinary =
9090
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
91-
layout.buildDirectory.file("image/smithy-cli-$imageOs/bin/smithy.bat").get().asFile.path
91+
layout.buildDirectory
92+
.file("image/smithy-cli-$imageOs/bin/smithy.bat")
93+
.get()
94+
.asFile.path
9295
} else {
93-
layout.buildDirectory.file("image/smithy-cli-$imageOs/bin/smithy").get().asFile.path
96+
layout.buildDirectory
97+
.file("image/smithy-cli-$imageOs/bin/smithy")
98+
.get()
99+
.asFile.path
94100
}
95101
System.setProperty("SMITHY_BINARY", smithyBinary)
96102

@@ -142,9 +148,10 @@ runtime {
142148
// is configured for the runtime
143149
// NOTE: For the runtime task, you *must* have the right JDK set up in your environment (17 at the time of writing)
144150
javaHome =
145-
javaToolchains.launcherFor {
146-
languageVersion.set(JavaLanguageVersion.of(imageJreVersion))
147-
}.map { it.metadata.installationPath.asFile.path }
151+
javaToolchains
152+
.launcherFor {
153+
languageVersion.set(JavaLanguageVersion.of(imageJreVersion))
154+
}.map { it.metadata.installationPath.asFile.path }
148155
}
149156

150157
tasks {

0 commit comments

Comments
 (0)