Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Marcono1234 opened this issue Jan 15, 2025 · 0 comments

Comments

@Marcono1234
Copy link

Marcono1234 commented Jan 15, 2025

Background: palantir/javapoet#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:

createOrUpdateIdeaXmlFile(
project.file(".idea/externalDependencies.xml"),
node -> ConfigureJavaFormatterXml.configureExternalDependencies(node));
createOrUpdateIdeaXmlFile(
project.file(".idea/workspace.xml"), node -> ConfigureJavaFormatterXml.configureWorkspaceXml(node));

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant