1+ import com.diffplug.spotless.FormatterFunc
12import com.github.spotbugs.snom.Effort
23import java.util.regex.Pattern
34import org.gradle.api.Project
45import org.gradle.kotlin.dsl.the
6+ import java.io.Serializable
57
68plugins {
79 `java- library`
@@ -75,15 +77,25 @@ spotless {
7577 // Enforce a common license header on all files
7678 licenseHeaderFile(" ${project.rootDir} /config/spotless/license-header.txt" )
7779 .onlyIfContentMatches(" ^((?!SKIPLICENSECHECK)[\\ s\\ S])*\$ " )
78- indentWithSpaces ()
80+ leadingTabsToSpaces ()
7981 endWithNewline()
8082
8183 eclipse().configFile(" ${project.rootDir} /config/spotless/formatting.xml" )
8284
8385 // Fixes for some strange formatting applied by eclipse:
8486 // see: https://github.com/kamkie/demo-spring-jsf/blob/bcacb9dc90273a5f8d2569470c5bf67b171c7d62/build.gradle.kts#L159
85- custom(" Lambda fix" ) { it.replace(" } )" , " })" ).replace(" } ," , " }," ) }
86- custom(" Long literal fix" ) { Pattern .compile(" ([0-9_]+) [Ll]" ).matcher(it).replaceAll(" \$ 1L" ) }
87+ // These have to be implemented with anonymous classes this way instead of lambdas because of:
88+ // https://github.com/diffplug/spotless/issues/2387
89+ custom(" Lambda fix" , object : Serializable , FormatterFunc {
90+ override fun apply (input : String ) : String {
91+ return input.replace(" } )" , " })" ).replace(" } ," , " }," )
92+ }
93+ })
94+ custom(" Long literal fix" , object : Serializable , FormatterFunc {
95+ override fun apply (input : String ) : String {
96+ return Pattern .compile(" ([0-9_]+) [Ll]" ).matcher(input).replaceAll(" \$ 1L" )
97+ }
98+ })
8799
88100 // Static first, then everything else alphabetically
89101 removeUnusedImports()
@@ -96,7 +108,7 @@ spotless {
96108 // Formatting for build.gradle.kts files
97109 kotlinGradle {
98110 ktlint()
99- indentWithSpaces ()
111+ leadingTabsToSpaces ()
100112 trimTrailingWhitespace()
101113 endWithNewline()
102114 }
0 commit comments