Add autoformat java sources into your gradle project
Task: Add autoformat sources into gradle file
Language: Java, Gradle
Implementation:
Add next blocks in the build.gradle file:
...
plugins {
...
id 'com.diffplug.spotless' version '6.25.0'
...
}
...
spotless {
java {
target fileTree('.') {
include '**/*.java'
exclude '**/build/**', '**/build-*/**'
}
toggleOffOn()
googleJavaFormat()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
...
compileJava.dependsOn 'spotlessApply'
...
As a result you will have formatted java sources.
Done.