@@ -303,6 +303,23 @@ tasks {
303303 delete(rootProject.file(" licenses" ))
304304 }
305305
306+ val trimLicenseTrailingWhitespace by registering {
307+ // trim trailing whitespace from license markdown file
308+ val licenseFile = rootDir.toPath().resolve(" licenses/licenses.md" )
309+ val newline = System .lineSeparator()
310+ doLast {
311+ if (Files .exists(licenseFile)) {
312+ val content = String (Files .readAllBytes(licenseFile), Charsets .UTF_8 )
313+ val normalized = content.lineSequence()
314+ .map { it.trimEnd() }
315+ .toList()
316+ .dropLastWhile { it.isEmpty() }
317+ .joinToString(newline) + newline
318+ Files .write(licenseFile, normalized.toByteArray(Charsets .UTF_8 ))
319+ }
320+ }
321+ }
322+
306323 val removeLicenseDate by registering {
307324 // removing the license report date makes it idempotent
308325 val rootDirPath = rootDir.toPath()
@@ -328,7 +345,7 @@ tasks {
328345 val generateLicenseReportTask = named(" generateLicenseReport" )
329346 generateLicenseReportTask.configure {
330347 dependsOn(cleanLicenses)
331- finalizedBy(" :spotlessApply " )
348+ finalizedBy(trimLicenseTrailingWhitespace )
332349 finalizedBy(removeLicenseDate)
333350 // disable licence report generation unless this task is explicitly run
334351 // the files produced by this task are used by other tasks without declaring them as dependency
0 commit comments