From 8e93bbde4b64c682a95fa7106fdc29c1cb66dca1 Mon Sep 17 00:00:00 2001 From: utzcoz Date: Sat, 15 Apr 2023 14:01:52 +0800 Subject: [PATCH] gradle: Integrate spotless to format Java and Kotlin code See https://github.com/diffplug/spotless. Signed-off-by: utzcoz --- build.gradle | 3 +++ src/xrt/auxiliary/android/build.gradle | 17 +++++++++++++++++ src/xrt/ipc/android/build.gradle | 18 ++++++++++++++++++ src/xrt/targets/android_common/build.gradle | 18 ++++++++++++++++++ src/xrt/targets/openxr_android/build.gradle | 19 +++++++++++++++++++ 5 files changed, 75 insertions(+) diff --git a/build.gradle b/build.gradle index 350ddee24..5dabb6947 100644 --- a/build.gradle +++ b/build.gradle @@ -52,6 +52,9 @@ plugins { // So we don't have to check in generated files: we start with SVGs for vector art. id "com.quittle.svg-2-android-vector" version "0.0.6" apply false + + // Spotless for Java and Kotlin's code formatting + id 'com.diffplug.spotless' version "6.18.0" apply false } ext { diff --git a/src/xrt/auxiliary/android/build.gradle b/src/xrt/auxiliary/android/build.gradle index a63589203..6bd044d42 100644 --- a/src/xrt/auxiliary/android/build.gradle +++ b/src/xrt/auxiliary/android/build.gradle @@ -5,6 +5,7 @@ plugins { id 'com.android.library' id 'kotlin-android' id 'dagger.hilt.android.plugin' + id 'com.diffplug.spotless' } android { @@ -49,3 +50,19 @@ dependencies { // Only a Java file has annotations right now, so we don't yet need kapt annotationProcessor "com.google.dagger:hilt-compiler:$hiltVersion" } + +spotless { + java { + target 'src/main/java/**/*.java' + // apply a specific flavor of google-java-format. + googleJavaFormat('1.8').aosp().reflowLongStrings() + // fix formatting of type annotations. + formatAnnotations() + } + + kotlin { + target 'src/main/java/**/*.kt' + // Use ktfmt(https://github.com/facebook/ktfmt) as the default Kotlin formatter. + ktfmt('0.43').kotlinlangStyle() + } +} diff --git a/src/xrt/ipc/android/build.gradle b/src/xrt/ipc/android/build.gradle index 33c5e81d2..3a07a9f21 100644 --- a/src/xrt/ipc/android/build.gradle +++ b/src/xrt/ipc/android/build.gradle @@ -7,6 +7,8 @@ plugins { id 'kotlin-kapt' id 'dagger.hilt.android.plugin' + + id 'com.diffplug.spotless' } android { @@ -64,3 +66,19 @@ dependencies { api "com.google.dagger:hilt-android:$hiltVersion" kapt "com.google.dagger:hilt-compiler:$hiltVersion" } + +spotless { + java { + target 'src/main/java/**/*.java' + // apply a specific flavor of google-java-format. + googleJavaFormat('1.8').aosp().reflowLongStrings() + // fix formatting of type annotations. + formatAnnotations() + } + + kotlin { + target 'src/main/java/**/*.kt' + // Use ktfmt(https://github.com/facebook/ktfmt) as the default Kotlin formatter. + ktfmt('0.43').kotlinlangStyle() + } +} diff --git a/src/xrt/targets/android_common/build.gradle b/src/xrt/targets/android_common/build.gradle index 9233d3bb8..eca59debf 100644 --- a/src/xrt/targets/android_common/build.gradle +++ b/src/xrt/targets/android_common/build.gradle @@ -11,8 +11,26 @@ plugins { // SVG files in the "raw" resource directory will be transformed into vector drawables of the same name. id 'com.quittle.svg-2-android-vector' + + // Use spotless to format Java and Kotlin code. + id 'com.diffplug.spotless' } +spotless { + java { + target 'src/main/java/**/*.java' + // apply a specific flavor of google-java-format. + googleJavaFormat('1.8').aosp().reflowLongStrings() + // fix formatting of type annotations. + formatAnnotations() + } + + kotlin { + target 'src/main/java/**/*.kt' + // Use ktfmt(https://github.com/facebook/ktfmt) as the default Kotlin formatter. . + ktfmt('0.43').kotlinlangStyle() + } +} android { compileSdk project.sharedCompileSdk diff --git a/src/xrt/targets/openxr_android/build.gradle b/src/xrt/targets/openxr_android/build.gradle index 1a2c9f925..1cb8984b8 100644 --- a/src/xrt/targets/openxr_android/build.gradle +++ b/src/xrt/targets/openxr_android/build.gradle @@ -17,6 +17,25 @@ plugins { // SVG files in the "raw" resource directory will be transformed into vector drawables of the same name. id 'com.quittle.svg-2-android-vector' + + // Use spotless to format Java and Kotlin code + id 'com.diffplug.spotless' +} + +spotless { + java { + target 'src/main/java/**/*.java' + // apply a specific flavor of google-java-format. + googleJavaFormat('1.8').aosp().reflowLongStrings() + // fix formatting of type annotations. + formatAnnotations() + } + + kotlin { + target 'src/main/java/**/*.kt' + // Use ktfmt(https://github.com/facebook/ktfmt) as the default Kotlin formatter. + ktfmt('0.43').kotlinlangStyle() + } } // apply from: file("../android_common/fetch-eigen.gradle")