What is the use of com.diffplug.spotless plugin in Android Studio?

Viewed 2048

I am working with Jetpack Compose and I came across "com.diffplug.spotless" plugin in the app's build.gradle file of many examples, but I am not sure if I need it in my project. Can anyone explain the purpose of using it in the Jetpack compose projects?

''' apply plugin: "com.diffplug.spotless" '''

1 Answers

Spotless: Keep your code spotless with Gradle

While working, Many a times you will get formatting issues at the stage of every commit like removing empty lines, cutting white spaces correct, indentation and other minor formatting mistakes. Using tool/plugin called “Spotless” will reduce time in addressing code review comments.

Spotless provides support for a variety of languages. Spotless consists of a list of format and each format has:-

1.a target (the files to format), which you set with target. 2.a list of FormatterStep, which are just String -> String functions, such as replace, replaceRegex, trimTrailingWhitespace, custom, prettier, eclipseWtp, licenseHeader etc.

To start integration with Gradle:-

1.Add the following dependency to your build.gradle file classpath(“com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion”)

2.Apply the following plugin apply plugin: ‘com.diffplug.gradle.spotless’

3.Applying spotless to your gradle file in Android Java source

spotless {
java {
  // ...
  target '**/*.java'
  // ...
}

}

Note:- Be sure to add target '**/*.java' otherwise spotless will not detect Java code inside Android modules.

For more detail you can refer this link : 1

Related