You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit faa27ea
Browse filesBrowse the repository at this point in the historyBrowse files
Show how to enable the IntelliJ plugin, format on save and use the native binary
Two screenshots: the open-java-format Settings page with the plugin enabled,
and Actions on Save with Reformat code for Java files and the whole file, the
scope the GitHub Action checks. A new section explains the native binary in
the IDE: it is switched on by openjavaformat.native.formatter in the Gradle
build, and the settings page then shows Native image formatter.
From then on Reformat Code, ++ctrl+alt+l++ or ++option+cmd+l++ on macOS, formats Java files with
42
44
open-java-format.
43
45
44
-
## Which formatter version runs
46
+
## Format on save
47
+
48
+
1. Open **Settings** and go to **Tools → Actions on Save**.
49
+
2. Tick **Reformat code**.
50
+
3. Next to it, choose **Java** in the file list and **Whole file** instead of **Changed lines**.
45
51
46
-
The formatter runs in a process of its own, on the IDE's runtime, so the project SDK can be any
47
-
version. When a Gradle build runs the formatter as a
48
-
[native binary](gradle.md#choose-how-the-formatter-runs), the IDE runs that binary instead.
52
+
{ width="1000" height="674" loading="lazy" }
53
+
54
+
Limiting it to Java keeps other files out: the IDE would reformat those with its own formatters.
55
+
**Whole file** formats the entire file, which is what the [GitHub Action](github-actions.md) checks.
56
+
**Changed lines** formats only the lines you edited, the way `formatDiff` does.
57
+
58
+
## Which formatter version runs
49
59
50
60
A project that applies the [Gradle plugin](gradle.md) takes the formatter version from the build.
51
-
Every other project uses the version bundled with the IDE plugin.
61
+
Every other project uses the version bundled with the IDE plugin, which the settings page shows as
62
+
`(bundled)` under **Implementation version**, as in the screenshot above.
63
+
64
+
By default the formatter runs in a process of its own, on the IDE's runtime, so the project SDK can
65
+
be any version.
66
+
67
+
## Native binary
68
+
69
+
In a project with the [Gradle plugin](gradle.md), the IDE can run the formatter as the native binary
70
+
that the build uses. It is switched on in the build, not in the IDE:
71
+
72
+
```properties title="gradle.properties"
73
+
openjavaformat.native.formatter=true
74
+
```
75
+
76
+
After the next Gradle sync in the IDE, the plugin writes the path of the binary into
77
+
`.idea/open-java-format.xml`, and **Formatter type** on the settings page changes from
78
+
**Java-based formatter** to **Native image formatter**. Each reformat starts the formatter as a new
79
+
process, and the native binary starts without a JVM.
80
+
81
+
The binary runs on the platforms listed on the
82
+
[Gradle plugin](gradle.md#choose-how-the-formatter-runs) page. Elsewhere the plugin ignores the
83
+
property, and the IDE keeps the Java-based formatter.
0 commit comments