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`
@@ -71,15 +73,25 @@ spotless {
7173 // Enforce a common license header on all files
7274 licenseHeaderFile(" ${project.rootDir} /config/spotless/license-header.txt" )
7375 .onlyIfContentMatches(" ^((?!SKIPLICENSECHECK)[\\ s\\ S])*\$ " )
74- indentWithSpaces ()
76+ leadingTabsToSpaces ()
7577 endWithNewline()
7678
7779 eclipse().configFile(" ${project.rootDir} /config/spotless/formatting.xml" )
7880
7981 // Fixes for some strange formatting applied by eclipse:
8082 // see: https://github.com/kamkie/demo-spring-jsf/blob/bcacb9dc90273a5f8d2569470c5bf67b171c7d62/build.gradle.kts#L159
81- custom(" Lambda fix" ) { it.replace(" } )" , " })" ).replace(" } ," , " }," ) }
82- custom(" Long literal fix" ) { Pattern .compile(" ([0-9_]+) [Ll]" ).matcher(it).replaceAll(" \$ 1L" ) }
83+ // These have to be implemented with anonymous classes this way instead of lambdas because of:
84+ // https://github.com/diffplug/spotless/issues/2387
85+ custom(" Lambda fix" , object : Serializable , FormatterFunc {
86+ override fun apply (input : String ) : String {
87+ return input.replace(" } )" , " })" ).replace(" } ," , " }," )
88+ }
89+ })
90+ custom(" Long literal fix" , object : Serializable , FormatterFunc {
91+ override fun apply (input : String ) : String {
92+ return Pattern .compile(" ([0-9_]+) [Ll]" ).matcher(input).replaceAll(" \$ 1L" )
93+ }
94+ })
8395
8496 // Static first, then everything else alphabetically
8597 removeUnusedImports()
@@ -92,7 +104,7 @@ spotless {
92104 // Formatting for build.gradle.kts files
93105 kotlinGradle {
94106 ktlint()
95- indentWithSpaces ()
107+ leadingTabsToSpaces ()
96108 trimTrailingWhitespace()
97109 endWithNewline()
98110 }
0 commit comments