@@ -5,6 +5,14 @@ plugins {
55 id " com.github.nbaztec.coveralls-jacoco" version " 1.2.20"
66}
77
8+ configurations {
9+ palantirJavaFormat
10+ }
11+
12+ dependencies {
13+ palantirJavaFormat " com.palantir.javaformat:palantir-java-format:2.69.0"
14+ }
15+
816allprojects {
917 apply plugin : " idea"
1018 apply plugin : " java-library"
@@ -174,3 +182,35 @@ coverallsJacoco {
174182 it. sourceSets. main. allSource. srcDirs
175183 }
176184}
185+
186+ def javaFormatSources = providers. provider {
187+ files(subprojects. collect { subproject ->
188+ subproject. fileTree(dir : subproject. projectDir) {
189+ include " src/**/*.java"
190+ }
191+ }). files. findAll { it. exists() }
192+ }
193+
194+ tasks. register(" formatJava" , JavaExec ) {
195+ group = " formatting"
196+ description = " Formats all Java sources with Palantir Java Format."
197+ classpath = configurations. palantirJavaFormat
198+ mainClass = " com.palantir.javaformat.java.Main"
199+ doFirst {
200+ args = [" --replace" ] + javaFormatSources. get(). collect { it. absolutePath }
201+ }
202+ }
203+
204+ tasks. register(" checkFormatJava" , JavaExec ) {
205+ group = " verification"
206+ description = " Checks whether all Java sources are formatted with Palantir Java Format."
207+ classpath = configurations. palantirJavaFormat
208+ mainClass = " com.palantir.javaformat.java.Main"
209+ doFirst {
210+ args = [" --dry-run" , " --set-exit-if-changed" ] + javaFormatSources. get(). collect { it. absolutePath }
211+ }
212+ }
213+
214+ tasks. named(" check" ) {
215+ dependsOn(tasks. named(" checkFormatJava" ))
216+ }
0 commit comments