Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 84 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import com.diffplug.spotless.FormatterFunc
import com.github.spotbugs.snom.Effort
import org.jreleaser.model.Active
import java.io.Serializable
import java.util.regex.Pattern

plugins {
`java-library`
Expand All @@ -24,6 +16,7 @@ plugins {
jacoco
id("com.github.spotbugs") version "6.3.0"
id("org.jreleaser") version "1.20.0"
id("com.diffplug.spotless") version "8.1.0"
}

allprojects {
Expand All @@ -34,7 +27,6 @@ allprojects {
// The root project doesn't produce a JAR.
tasks["jar"].enabled = false


repositories {
mavenLocal()
mavenCentral()
Expand Down Expand Up @@ -75,10 +67,11 @@ subprojects {
}

// Reusable license copySpec
val licenseSpec = copySpec {
from("${project.rootDir}/LICENSE")
from("${project.rootDir}/NOTICE")
}
val licenseSpec =
copySpec {
from("${project.rootDir}/LICENSE")
from("${project.rootDir}/NOTICE")
}

// Set up tasks that build source and javadoc jars.
tasks.register<Jar>("sourcesJar") {
Expand Down Expand Up @@ -127,7 +120,12 @@ subprojects {
repositories {
maven {
name = "stagingRepository"
url = rootProject.layout.buildDirectory.dir("staging").get().asFile.toURI()
url =
rootProject.layout.buildDirectory
.dir("staging")
.get()
.asFile
.toURI()
}
}

Expand Down Expand Up @@ -194,7 +192,9 @@ subprojects {
*
* Configure the running of tests.
*/

// Log on passed, skipped, and failed test events if the `-Plog-tests` property is set.

if (project.hasProperty("log-tests")) {
tasks.test {
testLogging {
Expand Down Expand Up @@ -226,7 +226,10 @@ subprojects {
xml.required.set(false)
csv.required.set(false)
html.outputLocation.set(
layout.buildDirectory.dir("reports/jacoco").get().asFile
layout.buildDirectory
.dir("reports/jacoco")
.get()
.asFile,
)
}
}
Expand All @@ -249,6 +252,62 @@ subprojects {
}
}
}

apply(plugin = "com.diffplug.spotless")

spotless {
java {
// Enforce a common license header on all files
licenseHeaderFile("${project.rootDir}/config/spotless/license-header.txt")
.onlyIfContentMatches("^((?!SKIPLICENSECHECK)[\\s\\S])*\$")
leadingTabsToSpaces()
endWithNewline()
eclipse().configFile("${project.rootDir}/config/spotless/formatting.xml")

// Fixes for some strange formatting applied by eclipse:
// see: https://github.com/kamkie/demo-spring-jsf/blob/bcacb9dc90273a5f8d2569470c5bf67b171c7d62/build.gradle.kts#L159
// These have to be implemented with anonymous classes this way instead of lambdas because of:
// https://github.com/diffplug/spotless/issues/2387
custom(
"Lambda fix",
object : Serializable, FormatterFunc {
override fun apply(input: String): String = input.replace("} )", "})").replace("} ,", "},")
},
)
custom(
"Long literal fix",
object : Serializable, FormatterFunc {
override fun apply(input: String): String = Pattern.compile("([0-9_]+) [Ll]").matcher(input).replaceAll("\$1L")
},
)

// Static first, then everything else alphabetically
removeUnusedImports()
importOrder("\\#", "")
// Ignore generated code for formatter check
targetExclude("*/build/**/*.*")
}

// Formatting for build.gradle.kts files
kotlinGradle {
ktlint()
leadingTabsToSpaces()
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(
"${project.rootDir}/config/spotless/license-header.txt",
"import|tasks|apply|plugins|rootProject",
)
}
tasks {
// If the property "noFormat" is set, don't auto-format source file (like in CI)
if (!project.hasProperty("noFormat")) {
build {
dependsOn(spotlessApply)
}
}
}
}
}

/*
Expand Down Expand Up @@ -290,10 +349,13 @@ jreleaser {
active = Active.ALWAYS
url = "https://central.sonatype.com/api/v1/publisher"
stagingRepositories.add(
rootProject.layout.buildDirectory.dir("staging").get().asFile.absolutePath
rootProject.layout.buildDirectory
.dir("staging")
.get()
.asFile.absolutePath,
)
}
}
}
}
}
}
Loading
Loading