|
| 1 | +# Migrate |
| 2 | + |
| 3 | +## From palantir-java-format |
| 4 | + |
| 5 | +open-java-format 2.98.0.1 is the code of palantir-java-format 2.98.0 under new names, built in the |
| 6 | +open. The output is the same, so switching produces no formatting diff and needs no reformatting |
| 7 | +commit. Checked on 132 source files, about 27,000 lines: both formatters give byte-identical output. |
| 8 | + |
| 9 | +The Java packages are unchanged as well. Only the names in your build and your scripts change. |
| 10 | + |
| 11 | +| | palantir-java-format | open-java-format | |
| 12 | +| --- | --- | --- | |
| 13 | +| Version | `2.98.0` | `2.98.0.1` | |
| 14 | +| Maven group | `com.palantir.javaformat` | `dev.openjavaformat` | |
| 15 | +| Formatter | `palantir-java-format` | `open-java-format` | |
| 16 | +| SPI | `palantir-java-format-spi` | `open-java-format-spi` | |
| 17 | +| Gradle plugin | `com.palantir.java-format` | `dev.openjavaformat.java-format` | |
| 18 | +| Gradle property | `palantir.native.formatter` | `openjavaformat.native.formatter` | |
| 19 | +| Command-line style flag | `--palantir` | `--ojf` | |
| 20 | +| Style in the API | `PALANTIR` | `OJF` | |
| 21 | +| IntelliJ plugin | `palantir-java-format` | `open-java-format` | |
| 22 | +| Java packages | `com.palantir.javaformat.*` | the same, for the whole 2.x line | |
| 23 | + |
| 24 | +The fourth number of the version counts builds of an upstream version: 2.98.0.1 is the first build |
| 25 | +of 2.98.0. |
| 26 | + |
| 27 | +### Gradle |
| 28 | + |
| 29 | +``` diff title="build.gradle" |
| 30 | + plugins { |
| 31 | +- id 'com.palantir.java-format' version '2.98.0' |
| 32 | ++ id 'dev.openjavaformat.java-format' version '2.98.0.1' |
| 33 | + } |
| 34 | +``` |
| 35 | + |
| 36 | +``` diff title="gradle.properties" |
| 37 | +-palantir.native.formatter=true |
| 38 | ++openjavaformat.native.formatter=true |
| 39 | +``` |
| 40 | + |
| 41 | +The plugin needs Gradle 9 and Java 21 or later. [Gradle plugin](get-started/gradle.md) covers the |
| 42 | +settings and multi-project builds. |
| 43 | + |
| 44 | +### Command line and scripts |
| 45 | + |
| 46 | +Replace `--palantir` with `--ojf`, and take the binary or the jar from |
| 47 | +[our releases](get-started/command-line.md). |
| 48 | + |
| 49 | +!!! warning "The old flag does not fail" |
| 50 | + |
| 51 | + `--palantir` is no longer accepted, but it is not an error either: the formatter prints |
| 52 | + `unexpected flag: --palantir` with its usage text and exits with 0. A CI step that still passes |
| 53 | + the old flag would go green without checking anything. Search your scripts and workflows for |
| 54 | + it. |
| 55 | + |
| 56 | +### Libraries that call the formatter |
| 57 | + |
| 58 | +Change the coordinates. The imports stay as they are, because the packages did not move. |
| 59 | + |
| 60 | +``` diff title="build.gradle" |
| 61 | +-implementation 'com.palantir.javaformat:palantir-java-format:2.98.0' |
| 62 | ++implementation 'dev.openjavaformat:open-java-format:2.98.0.1' |
| 63 | +``` |
| 64 | + |
| 65 | +In a `pom.xml` it is the same change of `groupId`, `artifactId` and `version`. |
| 66 | + |
| 67 | +### IntelliJ IDEA |
| 68 | + |
| 69 | +1. Disable or uninstall the palantir-java-format plugin. Both plugins take over **Reformat Code** |
| 70 | + for Java, so only one of them should be enabled. |
| 71 | +2. Install [open-java-format](get-started/intellij-idea.md) from the JetBrains Marketplace. |
| 72 | +3. Enable it for the project again. The setting now lives in `.idea/open-java-format.xml`, and the |
| 73 | + old `.idea/palantir-java-format.xml` is ignored and can be deleted. A project that applies the |
| 74 | + Gradle plugin gets the new file written when it is imported. |
| 75 | + |
| 76 | +### Eclipse |
| 77 | + |
| 78 | +Remove `palantir-java-format-eclipse-plugin-*.jar` from the `dropins` folder and follow |
| 79 | +[Eclipse](get-started/eclipse.md) for the new jar. The `--add-exports` lines in `eclipse.ini` stay. |
| 80 | + |
| 81 | +## From google-java-format |
| 82 | + |
| 83 | +The style is different, so this migration comes with one reformatting commit. Lines go from 100 to |
| 84 | +120 columns, indentation from 2 to 4 spaces, a lambda stays on the line where it starts, and a long |
| 85 | +call chain breaks into one call per line. The [home page](index.md#what-the-output-looks-like) shows |
| 86 | +the same method in both styles. |
| 87 | + |
| 88 | +1. Set the formatter up: [Get started](get-started/index.md). The `--add-exports` JVM flags you may |
| 89 | + already have for google-java-format are the same. |
| 90 | +2. Format everything once and commit only that: |
| 91 | + |
| 92 | + ``` sh |
| 93 | + open-java-format --ojf --replace $(git ls-files '*.java') |
| 94 | + git commit -am "Reformat with open-java-format" |
| 95 | + ``` |
| 96 | + |
| 97 | +3. Keep `git blame` useful by listing that commit in `.git-blame-ignore-revs`: |
| 98 | + |
| 99 | + ``` sh |
| 100 | + git rev-parse HEAD >> .git-blame-ignore-revs |
| 101 | + git add .git-blame-ignore-revs |
| 102 | + git commit -m "Ignore the reformatting commit in blame" |
| 103 | + git config blame.ignoreRevsFile .git-blame-ignore-revs |
| 104 | + ``` |
| 105 | + |
| 106 | + GitHub reads that file on its own. The `git config` line is for local clones, and each |
| 107 | + developer runs it once. |
| 108 | + |
| 109 | +4. In IntelliJ IDEA disable the google-java-format plugin before enabling |
| 110 | + [open-java-format](get-started/intellij-idea.md). |
0 commit comments