gradle: Integrate spotless to format Java and Kotlin code

See https://github.com/diffplug/spotless.

Signed-off-by: utzcoz <utzcoz@outlook.com>
This commit is contained in:
utzcoz 2023-04-15 14:01:52 +08:00 committed by Ryan Pavlik
parent e3d345d428
commit 8e93bbde4b
5 changed files with 75 additions and 0 deletions

View file

@ -52,6 +52,9 @@ plugins {
// So we don't have to check in generated files: we start with SVGs for vector art. // 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 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 { ext {

View file

@ -5,6 +5,7 @@ plugins {
id 'com.android.library' id 'com.android.library'
id 'kotlin-android' id 'kotlin-android'
id 'dagger.hilt.android.plugin' id 'dagger.hilt.android.plugin'
id 'com.diffplug.spotless'
} }
android { android {
@ -49,3 +50,19 @@ dependencies {
// Only a Java file has annotations right now, so we don't yet need kapt // Only a Java file has annotations right now, so we don't yet need kapt
annotationProcessor "com.google.dagger:hilt-compiler:$hiltVersion" 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()
}
}

View file

@ -7,6 +7,8 @@ plugins {
id 'kotlin-kapt' id 'kotlin-kapt'
id 'dagger.hilt.android.plugin' id 'dagger.hilt.android.plugin'
id 'com.diffplug.spotless'
} }
android { android {
@ -64,3 +66,19 @@ dependencies {
api "com.google.dagger:hilt-android:$hiltVersion" api "com.google.dagger:hilt-android:$hiltVersion"
kapt "com.google.dagger:hilt-compiler:$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()
}
}

View file

@ -11,8 +11,26 @@ plugins {
// SVG files in the "raw" resource directory will be transformed into vector drawables of the same name. // SVG files in the "raw" resource directory will be transformed into vector drawables of the same name.
id 'com.quittle.svg-2-android-vector' 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 { android {
compileSdk project.sharedCompileSdk compileSdk project.sharedCompileSdk

View file

@ -17,6 +17,25 @@ plugins {
// SVG files in the "raw" resource directory will be transformed into vector drawables of the same name. // SVG files in the "raw" resource directory will be transformed into vector drawables of the same name.
id 'com.quittle.svg-2-android-vector' 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") // apply from: file("../android_common/fetch-eigen.gradle")