How to Add Spotless Code Formatter to your Android Project?

Steps-by-steps guide to add spotless code formatter to your Android project for both Kotlin script (KTS) and Groovy build Gradle files

Vincent Tsen
3 min readJul 8, 2023

I have been seeing this spotless in many open-source codes, and it turns out it is a pretty popular coding style plugin for the Gradle build system used in Android development.

So I gave it a try and use it in my project. Here are the steps I took to add this spotless plugin to my existing projects, which consist of both Kotlin script (KTS) and Groovy build Gradle files.

1. Add com.diffplug.spotless Plugin

Add com.diffplug.spotless in the project-level build.gradle/.kts.

KTS

plugins {
/*...*/
id("com.diffplug.spotless") version "6.19.0" apply false
}

Groovy

plugins {
/*...*/
id 'com.diffplug.spotless' version '6.19.0' apply false
}

2. Configure the Spotless

Add the following at the end of your project-level build.gradle/.kts.

KTS

subprojects {
apply(plugin = "com.diffplug.spotless")…

--

--