summaryrefslogtreecommitdiff
path: root/buildSrc/src/main
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-06 13:13:10 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-06 14:46:56 +0200
commit47357afd16f928260db34d4dd3e686fb9ee7c5ff (patch)
tree950ba678869ec868c26ab3b95b57e4cabadb23c7 /buildSrc/src/main
parent402a8f55342c4565431c2a2e7287a70592f3fe33 (diff)
build: Switch to Spotless for formatting
This change updates the build configuration to use Spotless for code formating of both Kotlin and Java.
Diffstat (limited to 'buildSrc/src/main')
-rw-r--r--buildSrc/src/main/kotlin/java-conventions.gradle.kts1
-rw-r--r--buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts8
-rw-r--r--buildSrc/src/main/kotlin/license.kt22
-rw-r--r--buildSrc/src/main/kotlin/quarkus-conventions.gradle.kts10
-rw-r--r--buildSrc/src/main/kotlin/spotless-conventions.gradle.kts59
5 files changed, 83 insertions, 17 deletions
diff --git a/buildSrc/src/main/kotlin/java-conventions.gradle.kts b/buildSrc/src/main/kotlin/java-conventions.gradle.kts
index d4cc667a..a639a9e1 100644
--- a/buildSrc/src/main/kotlin/java-conventions.gradle.kts
+++ b/buildSrc/src/main/kotlin/java-conventions.gradle.kts
@@ -22,6 +22,7 @@
plugins {
`java-library`
+ id("spotless-conventions")
}
/* Project configuration */
diff --git a/buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts b/buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts
index 8fb46f5d..5ccc06a4 100644
--- a/buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts
+++ b/buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("java-conventions")
kotlin("jvm")
- id("org.jlleitschuh.gradle.ktlint")
+ id("spotless-conventions")
}
/* Project configuration */
@@ -34,9 +34,3 @@ tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
kotlinOptions.freeCompilerArgs += "-Xjvm-default=all"
}
-
-configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
- // Higher versions currently have issues with formatting where wildcard imports are automatically removed,
- // even when in use.
- version.set("0.42.1")
-}
diff --git a/buildSrc/src/main/kotlin/license.kt b/buildSrc/src/main/kotlin/license.kt
new file mode 100644
index 00000000..4e90fd4e
--- /dev/null
+++ b/buildSrc/src/main/kotlin/license.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) $YEAR AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
diff --git a/buildSrc/src/main/kotlin/quarkus-conventions.gradle.kts b/buildSrc/src/main/kotlin/quarkus-conventions.gradle.kts
index 75c4a454..f1adb182 100644
--- a/buildSrc/src/main/kotlin/quarkus-conventions.gradle.kts
+++ b/buildSrc/src/main/kotlin/quarkus-conventions.gradle.kts
@@ -76,13 +76,3 @@ configurations.create("coverageDataElementsForQuarkus") {
}
}
}
-
-/* Fix for Quarkus/ktlint-gradle incompatibilities */
-tasks.named("runKtlintCheckOverMainSourceSet") {
- mustRunAfter(tasks.quarkusGenerateCode)
- mustRunAfter(tasks.quarkusGenerateCodeDev)
-}
-
-tasks.named("runKtlintCheckOverTestSourceSet") {
- mustRunAfter(tasks.quarkusGenerateCodeTests)
-}
diff --git a/buildSrc/src/main/kotlin/spotless-conventions.gradle.kts b/buildSrc/src/main/kotlin/spotless-conventions.gradle.kts
new file mode 100644
index 00000000..11131cc8
--- /dev/null
+++ b/buildSrc/src/main/kotlin/spotless-conventions.gradle.kts
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2022 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+plugins {
+ id("com.diffplug.spotless")
+}
+
+spotless {
+ pluginManager.withPlugin("java") {
+ java {
+ importOrder()
+ removeUnusedImports()
+
+ palantirJavaFormat()
+
+ trimTrailingWhitespace()
+ endWithNewline()
+
+ licenseHeaderFile(rootProject.file("buildSrc/src/main/kotlin/license.kt"))
+ }
+ }
+
+ pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
+ kotlin {
+ ktlint()
+ .setUseExperimental(false)
+ trimTrailingWhitespace()
+ endWithNewline()
+
+ licenseHeaderFile(rootProject.file("buildSrc/src/main/kotlin/license.kt"))
+ }
+ }
+
+ kotlinGradle {
+ ktlint()
+
+ trimTrailingWhitespace()
+ endWithNewline()
+ }
+}