@@ -31,7 +31,9 @@ formatter version as the build. It needs Gradle 9 and a Gradle daemon running on
3131 }
3232 ```
3333
34- The formatter itself is downloaded from Maven Central, in the same version as the plugin.
34+ The formatter comes inside the plugin, in the plugin's own version: the build declares nothing for it
35+ and needs no repository for it. The repository above is for the build's own dependencies, and for the
36+ native binary below.
3537
3638## Choose how the formatter runs
3739
@@ -45,7 +47,10 @@ the two settings below; without either, `formatDiff` stops before the first file
4547 ```
4648
4749 Gradle then runs the formatter as a native binary, outside its own JVM. This works on Linux
48- with glibc, on macOS and on Windows on x86-64.
50+ with glibc, on macOS and on Windows on x86-64. The binary, some 60 MB, is
51+ `dev.openjavaformat:open-java-format-native` from Maven Central: each project that formats
52+ resolves it through its own repositories, `mavenCentral()` or a mirror of it, and runs a copy
53+ kept in `~/.gradle/open-java-format-caches`.
4954
5055=== "On the Gradle JVM"
5156
@@ -74,8 +79,9 @@ With a clean working tree it has nothing to do.
7479
7580## Multi-project builds
7681
77- Declare the plugin once in the root project and apply it wherever there is Java code. The formatter
78- is resolved by the root project, so the root project needs the repository too.
82+ Declare the plugin once in the root project and apply it wherever there is Java code. Each project
83+ resolves what it needs through its own repositories, so the root project needs none; a parallel
84+ build (` --parallel ` ) works too.
7985
8086=== "Groovy"
8187
@@ -84,15 +90,13 @@ is resolved by the root project, so the root project needs the repository too.
8490 id 'dev.openjavaformat.java-format' version '{{ ojf_version }}' apply false
8591 }
8692
87- allprojects {
88- repositories {
89- mavenCentral()
90- }
91- }
92-
9393 subprojects {
9494 apply plugin: 'java'
9595 apply plugin: 'dev.openjavaformat.java-format'
96+
97+ repositories {
98+ mavenCentral()
99+ }
96100 }
97101 ```
98102
@@ -103,15 +107,13 @@ is resolved by the root project, so the root project needs the repository too.
103107 id("dev.openjavaformat.java-format") version "{{ ojf_version }}" apply false
104108 }
105109
106- allprojects {
107- repositories {
108- mavenCentral()
109- }
110- }
111-
112110 subprojects {
113111 apply(plugin = "java")
114112 apply(plugin = "dev.openjavaformat.java-format")
113+
114+ repositories {
115+ mavenCentral()
116+ }
115117 }
116118 ```
117119
@@ -131,6 +133,40 @@ Up to 21.0.1, `formatDiff` and the Spotless step fail with the cache on
131133Gradle's own ` idea ` task does not support the cache, and Gradle turns it off for a build that runs
132134the task.
133135
136+ ## Build cache
137+
138+ The [ Spotless] ( spotless.md ) task ` spotlessJava ` is cacheable, and the formatter is part of its cache
139+ key: another formatter version runs the task again, while a copy of the project in another directory,
140+ or on another machine, takes the result from the cache. A build that cannot run the formatter, for
141+ want of the ` --add-exports ` flags above, fails ` spotlessJava ` and leaves nothing in the cache.
142+
143+ Up to 21.0.1, the key did not change with the formatter version, and a failure of the formatter went
144+ into the cache as the task's result.
145+
146+ ## Another formatter version
147+
148+ The plugin formats with the version that comes inside it. To try another one, declare it in the root
149+ project. Each project that formats resolves it through its own repositories, and so does the root
150+ project, for the IntelliJ IDEA settings below:
151+
152+ === "Groovy"
153+
154+ ``` groovy title="build.gradle"
155+ dependencies {
156+ palantirJavaFormat 'dev.openjavaformat:open-java-format:<version>'
157+ }
158+ ```
159+
160+ === "Kotlin"
161+
162+ ``` kotlin title="build.gradle.kts"
163+ dependencies {
164+ "palantirJavaFormat"("dev.openjavaformat:open-java-format:<version>")
165+ }
166+ ```
167+
168+ The IntelliJ IDEA settings below then name that version too.
169+
134170## IntelliJ IDEA
135171
136172When the project is opened in IntelliJ IDEA, the plugin writes the formatter settings into ` .idea ` ,
0 commit comments