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 16, 2023
1 parent 0272226 commit 508bcc6
Show file tree
Hide file tree
Showing 2 changed files with 25 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
25 changes: 24 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,28 @@ java {
}
}

spotless {
java {
toggleOffOn()
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 508bcc6

Please sign in to comment.