-
Notifications
You must be signed in to change notification settings - Fork 488
feat: add IntelliJ IDEA formatter #2535
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
Conversation
Thought of implementation plan, experimented with code dependencies using tests.
Added parameterized method to call idea formatter.
Used ForeignExe to check idea binary
IDEA running using gradle
IDEA running using maven
As described here: diffplug#200 (comment)
This part is lacking tests due to unpredictable nature of IDEA formatting. They may change configs thus breaking build.
This object is now resides in IdeaStep
…llij-formatter # Conflicts: # CHANGES.md # plugin-gradle/CHANGES.md # plugin-maven/CHANGES.md
as it can handle various file formats besides java.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Introduces support for using IntelliJ IDEA’s command-line formatter in Spotless, including both Maven and Gradle plugins, test harness enhancements, and CI integration.
- Add
IdeaStepimplementation and test environment overrides for custom IDEA binary and code style settings. - Integrate IDEA formatter into Maven (
<idea>) and Gradle (idea()) DSLs, plus documentation and changelogs. - Enhance test infrastructure (
@IdeaTest,TestEnvVars, CI matrix) to run IDEA-based formatting tests.
Reviewed Changes
Copilot reviewed 24 out of 26 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| testlib/src/test/java/com/diffplug/spotless/generic/IdeaStepTest.java | Adds unit tests for IdeaStep behavior |
| testlib/src/main/resources/java/idea/full.dirty.java | Dirty Java sample for IDEA formatting tests |
| testlib/src/main/resources/java/idea/full.clean.java | Clean Java sample for IDEA formatting tests |
| testlib/src/main/java/com/diffplug/spotless/tag/IdeaTest.java | Introduces @IdeaTest JUnit tag |
| testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java | Adds hasDifferentContent / notSameAsResource helpers |
| plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/IdeaTest.java | Maven integration test for IDEA formatter |
| plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java | Extend MavenRunner to propagate system properties |
| plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java | Propagate spotless* properties into Maven test runs |
| plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Idea.java | Implements Maven FormatterStepFactory for IDEA |
| plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java | Registers IDEA step in Maven formatter factory |
| plugin-maven/build.gradle | Pass spotlessProjectDir system property for IDEA tests |
| plugin-maven/README.md | Document IDEA support in Maven plugin |
| plugin-maven/CHANGES.md | Changelog entry for new IDEA support |
| plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaIdeaTest.java | Gradle integration test for IDEA formatter |
| plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java | Minor comment fix |
| plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java | Adds idea() DSL and IdeaConfig for IDEA formatting |
| plugin-gradle/README.md | Document IDEA support in Gradle plugin |
| plugin-gradle/CHANGES.md | Changelog entry for new IDEA support |
| lib/src/main/java/com/diffplug/spotless/generic/TestEnvVars.java | Implements loading of testenv.properties for overrides |
| lib/src/main/java/com/diffplug/spotless/generic/IdeaStep.java | Core implementation of the IDEA formatting step |
| gradle/special-tests.gradle | Include idea in special test suite |
| INTELLIJ_IDEA_SCREENSHOTS.md | Add docs for extracting IDEA code style settings |
| .github/workflows/ci.yml | Add CI matrix entry and steps to run IDEA-based tests |
Comments suppressed due to low confidence (3)
plugin-maven/README.md:41
- [nitpick] Remove the stray
// TODO add ideacomment in the Languages section header; the documentation already includes IDEA, so clean up the header to avoid confusion.
- **Languages** // TODO add idea
testlib/src/test/java/com/diffplug/spotless/generic/IdeaStepTest.java:82
- [nitpick] The test method name
formattingsWithOutDefaultDoesNothinghas inconsistent casing and a typo (WithOut); consider renaming it toformattingWithoutDefaultsDoesNothingfor clarity.
void formattingsWithOutDefaultDoesNothing() throws Exception {
testlib/src/test/java/com/diffplug/spotless/generic/IdeaStepTest.java:115
- [nitpick] Consider adding tests for custom
binaryPathandcodeStyleSettingsPathbuilder options to verify that overrides are applied correctly.
}
|
amazing feat thanks.
|
The implementation uses IntelliJ's command line interface for formatting. So no, there is no support for inspections atm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing! This LGTM. If you're happy with it too then press merge and I'll cut a release this week.
|
Awesome! I'll go ahead and merge it then 😄 |
|
Released in |

This PR is based on @IlyasYOY work in #2020 🙏
It adds IntelliJ IDEA as a formatter for both gradle- and maven-plugin.
The implementation uses IntelliJ IDEA's formatting cli behind the scenes as intended by IntelliJ IDEA.
To make sure the IntelliJ IDEA instance launched by spotless is not interfering with a already running instance, we specify separated paths for
idea.config.pathandidea.system.pathusing a customidea.propertiesfile (seecom.diffplug.spotless.generic.IdeaStep.State#createIdeaPropertiesFile).For development, I've introduced a way to override the idea binary in a
testenv.propertiesfile since I do not find it feasible to add IDEA to my path just for this case.I've tried adding a CI-step to let IDEA-tests run in CI. This part is untested and I'll work on it when the implementation is deemed feasible.