Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Spotless configuration for Java #2485

Merged
merged 7 commits into from
Dec 20, 2024
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
distribution: 'corretto'

- name: Clean, build, test, and javadoc
run: ./gradlew clean build javadoc -Plog-tests --stacktrace
run: ./gradlew clean build javadoc -PnoFormat -Plog-tests --stacktrace

- name: Allow long file names in git for windows
if: matrix.os == 'windows-latest'
Expand Down
1 change: 0 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies {
implementation(libs.spotbugs)
implementation(libs.spotless)
implementation(libs.jmh)

// https://github.com/gradle/gradle/issues/15383
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import java.util.regex.Pattern

plugins {
checkstyle
id("com.diffplug.spotless")
}

// TODO: Add spotless java configuration
/*
* Formatting
* ==================
* see: https://github.com/diffplug/spotless/blob/main/plugin-gradle/README.md
*/
spotless {
java {
// Enforce a common license header on all files
licenseHeaderFile("${project.rootDir}/config/spotless/license-header.txt")
.onlyIfContentMatches("^((?!SKIPLICENSECHECK)[\\s\\S])*\$")
indentWithSpaces()
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
custom("Lambda fix") { it.replace("} )", "})").replace("} ,", "},") }
custom("Long literal fix") { Pattern.compile("([0-9_]+) [Ll]").matcher(it).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()
Expand All @@ -21,4 +39,12 @@ spotless {
"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)
}
}
}
}
6 changes: 0 additions & 6 deletions buildSrc/src/main/kotlin/smithy.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ if (project.hasProperty("log-tests")) {
}
}

// ==== CheckStyle ====
// https://docs.gradle.org/current/userguide/checkstyle_plugin.html
tasks.named("checkstyleTest") {
enabled = false
}

// ==== Code coverage ====
// https://docs.gradle.org/current/userguide/jacoco_plugin.html

Expand Down
200 changes: 0 additions & 200 deletions config/checkstyle/checkstyle.xml

This file was deleted.

31 changes: 0 additions & 31 deletions config/checkstyle/suppressions.xml

This file was deleted.

Loading
Loading