Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions docs/get-started/gradle.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,41 @@ build (`--parallel`) works too.
}
```

## Android projects

In an Android module, apply the plugin next to the Android Gradle plugin, 9.1 or later:
`com.android.application`, `com.android.library`, `com.android.dynamic-feature` or
`com.android.test`. These do not apply `java`, and the plugin does not need it there.

=== "Groovy"

``` groovy title="app/build.gradle"
plugins {
id 'com.android.application'
id 'dev.openjavaformat.java-format'
}
```

=== "Kotlin"

``` kotlin title="app/build.gradle.kts"
plugins {
id("com.android.application")
id("dev.openjavaformat.java-format")
}
```

`formatDiff` and the [Spotless](spotless.md) step then cover the Java files in the `java`
directories of every Android source set: `main`, `test`, `androidTest`, and those of the build
types and flavors. Java files in the `kotlin` directories are left out. The plugin reads the source
sets from the build's own Android Gradle plugin and brings none of its own, and it needs no Android
SDK.

!!! warning "Up to 21.1.1: nothing in Android modules"

The plugin did nothing in a module without the `java` plugin: there was no `formatDiff`, and
`spotlessCheck` passed whatever the files held.

## Configuration cache

The plugin works with Gradle's configuration cache: `formatDiff`, the [Spotless](spotless.md) step
Expand Down
3 changes: 3 additions & 0 deletions docs/get-started/spotless.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Apply both plugins. Ours adds an `open-java-format` step to the `java` format of
so the `spotless` block needs no formatter step. If it still calls `palantirJavaFormat()`, remove
that line.

In an [Android module](gradle.md#android-projects) the step formats the Java files of the Android
source sets. A `target` in the `spotless` block replaces them.

=== "Groovy"

``` groovy title="build.gradle"
Expand Down