palantir / palantir/palantir-java-format

Gradle plugin modifies IntelliJ config, even when IntelliJ plugin is not installed

Open
#1,190 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
907
Forks
101
Avg merge
1d 3h
Merged PRs (30d)
19

Description

Background: https://github.com/palantir/javapoet/issues/86
Related to #1111

Description

When you import a project which uses the palantir-java-format Gradle plugin in IntelliJ, it asks you to install the palantir-java-format IntelliJ plugin. However, as external (non-Palantir) contributor you might not want to do this, for example because you just want to make one small change and because you are not familiar with that IntelliJ plugin and whether it disrupts your other work.
Instead you might just want to run one formatting command (Spotless?) once you are done, before committing your changes.

The problem is that the palantir-java-format Gradle plugin on build modifies the IntelliJ project configuration:
https://github.com/palantir/palantir-java-format/blob/428c6fe4d1be132602a1e5ef8b1ea0d61e53ad7d/gradle-palantir-java-format/src/main/groovy/com/palantir/javaformat/gradle/PalantirJavaFormatIdeaPlugin.java#L90-L94

That by itself might already be a bit questionable, but what is worse is that this happens even if you don't have the palantir-java-format IntelliJ plugin installed. This makes IntelliJ format the code based on its own formatting configuration, causing large diffs in the worst case. And the Gradle plugin keeps enabling the auto-formatting every Gradle build, even if you disable it again in the IntelliJ settings. For you as user this feels like you are constantly fighting IntelliJ's auto-formatting until you notice that the palantir-java-format Gradle plugin keeps enabling it.

I assume you can imagine what a horrible experience this is for external contributors.

So please, if this Gradle plugin really needs to make changes to the IntelliJ project config, consider doing this only if the user has the IntelliJ plugin installed.

How to reproduce
  1. Make sure you don't have palantir-java-format IntelliJ plugin installed yet
  2. Import for example https://github.com/palantir/javapoet
  3. Build the project using Gradle (normally happens on import)
  4. Make changes in any of the .java source files, for example CodeBlock.java
  5. Commit the changes
    ❌ Issue: Notice how it reformatted the file, in a way not compatible with the Palantir formatting
  6. Check the "Actions on Save" of IntelliJ
    ❌ Issue: Notice how "Reformat code" and "Optimize imports" were automatically enabled
  7. Disable these settings
  8. Perform a Gradle build again, e.g. by running tests
  9. Check the "Actions on Save" of IntelliJ
    ❌ Issue: Notice how the settings "Reformat code" and "Optimize imports" were automatically enabled again

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with gradle-palantir-java-format/src/main/groovy/com/palantir/javaformat/gradle/PalantirJavaFormatIdeaPlugin.java, especially the linked configuration code. Reproduce the behavior by importing javapoet without the IntelliJ plugin, then building and checking IntelliJ's Actions on Save settings. Done means the Gradle plugin no longer enables these settings when the IntelliJ plugin is absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.