Skip to content

Conversation

@simschla
Copy link
Contributor

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.path and idea.system.path using a custom idea.properties file (see com.diffplug.spotless.generic.IdeaStep.State#createIdeaPropertiesFile).

For development, I've introduced a way to override the idea binary in a testenv.properties file 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.

IlyasYOY and others added 30 commits January 11, 2024 18:04
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
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.
@simschla simschla requested a review from Copilot June 30, 2025 14:15
Copy link
Contributor

Copilot AI left a 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 IdeaStep implementation 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 idea comment 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 formattingsWithOutDefaultDoesNothing has inconsistent casing and a typo (WithOut); consider renaming it to formattingWithoutDefaultsDoesNothing for clarity.
	void formattingsWithOutDefaultDoesNothing() throws Exception {

testlib/src/test/java/com/diffplug/spotless/generic/IdeaStepTest.java:115

  • [nitpick] Consider adding tests for custom binaryPath and codeStyleSettingsPath builder options to verify that overrides are applied correctly.
}

@Pankraz76
Copy link
Contributor

Pankraz76 commented Jul 1, 2025

amazing feat thanks.

  • How will it effect the code later on?
    • Can we apply specific inspections as well?
    • Or does it just apply the default format settings imposed by idea?

@simschla
Copy link
Contributor Author

simschla commented Jul 1, 2025

amazing feat thanks.

  • How will it effect the code later on?

    • Can we apply specific inspections as well?
    • Or does it just apply the default format settings imposed by idea?
image

The implementation uses IntelliJ's command line interface for formatting. So no, there is no support for inspections atm.

Copy link
Member

@nedtwigg nedtwigg left a 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.

@simschla
Copy link
Contributor Author

simschla commented Jul 2, 2025

Awesome! I'll go ahead and merge it then 😄

@simschla simschla merged commit 626a3d1 into diffplug:main Jul 2, 2025
17 checks passed
@simschla simschla deleted the feature/intellij-formatter branch July 2, 2025 12:39
@nedtwigg
Copy link
Member

nedtwigg commented Jul 7, 2025

Released in plugin-gradle 7.1.0 and plugin-maven 2.45.0.

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

Successfully merging this pull request may close these issues.

4 participants