Skip to content

Commit

Permalink
build.gradle: add spotless plugin
Browse files Browse the repository at this point in the history
This adds the build support for formatting-checks
in CI. Run with:

./gradlew spotlessCheck -PclangFormat=clang-format-15

to use a different clang-format binary, or put:

clangFormat = clang-format-15

in gradle.properties.
  • Loading branch information
pjonsson committed Oct 15, 2023
1 parent 7183bdc commit c5feb72
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
.gradle_home
*~
build
gradle.properties
/dist
/javadoc
28 changes: 27 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'application'
id 'application'
id 'com.diffplug.spotless' version '6.22.0'
}

group = 'org.contikios.cooja'
Expand All @@ -12,6 +13,31 @@ java {
}
}

spotless {
java {
toggleOffOn()
// Removing unused imports fails with unterminated string literal in
// GUI.java. The line is a switch statement with a string case, so
// possibly something to do with Java 17.
// removeUnusedImports()
importOrder()
// trimTrailingWhitespace()
// cleanthat()
// formatAnnotations()

// Use a different clang-format binary with -PclangFormat=clang-format-15.
def clangFormatBinary = (String) project.findProperty('clangFormat') ?: 'clang-format'
def clangOutput = new ByteArrayOutputStream()
exec {
commandLine clangFormatBinary, '--version'
standardOutput = clangOutput
}
def clangVersion = (String) (clangOutput.toString() =~ /\d+\.\d+\.\d+/)[0]
// FIXME: enable clangFormat in the future.
// clangFormat(clangVersion).pathToExe(clangFormatBinary).style('file')
}
}

repositories {
mavenCentral()
}
Expand Down

0 comments on commit c5feb72

Please sign in to comment.