GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support removing wildcard imports via `removeWildcardImports` step by iddeepak · Pull Request #2517 · diffplug/spotless

Conversation

@iddeepak

@iddeepak iddeepak commented Jun 18, 2025 •
edited by Goooler
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

I have just opened a PR to help us say “goodbye” to those sneaky wildcard imports (like import java.util.*;) whenever Spotless tidies up our Java files. Wildcard imports can make it hard to see exactly which classes you’re relying on, so this change introduces a new step in the Spotless plugin that:

Spots any import foo.*; lines in your source

Removes them outright (so your IDE or build tools can regenerate only the exact imports you need)

  • Closes Unused wild card imports are not removed #240.
  • Closes Add remove wildcards imports when formating and ordering imports. #649.
  • Closes spotless maven eclipse jdt - How to block import star (*) wildcard? #832.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tsaglam reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@iddeepak
Remove wildcard imports
69a5684
@iddeepak iddeepak mentioned this pull request Jun 19, 2025
Add remove wildcards imports when formating and ordering imports. #649
Closed
Pankraz76
Pankraz76 approved these changes Jun 19, 2025
View reviewed changes

@Pankraz76 Pankraz76 left a comment

Copy link
Copy Markdown

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.

awesome, thanks.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread plugin-gradle/README.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread testlib/src/main/resources/java/removewildcardimports/JavaCodeWildcardsUnformatted.test Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread plugin-maven/src/test/java/com/diffplug/spotless/maven/java/RemoveWildcardImportsStepTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

iddeepak and others added 2 commits June 20, 2025 01:19
@iddeepak @Pankraz76
Update plugin-gradle/README.md
ad37473
Co-authored-by: Consequences of Lacking Discipline <[email protected]>
@iddeepak @Pankraz76
Update testlib/src/main/resources/java/removewildcardimports/JavaCode…
205974a
…WildcardsUnformatted.test

Co-authored-by: Consequences of Lacking Discipline <[email protected]>
@iddeepak
iddeepak marked this pull request as ready for review June 19, 2025 21:33
Goooler
Goooler approved these changes Jun 23, 2025
View reviewed changes

@Goooler Goooler left a comment

Copy link
Copy Markdown
Member

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.

LGTM! Would you mind adding a test for the Gradle plugin?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread CHANGES.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread plugin-gradle/CHANGES.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread plugin-maven/CHANGES.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/src/main/java/com/diffplug/spotless/java/RemoveWildcardImportsStep.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Goooler
Apply suggestions from code review
0761c81
@Pankraz76 Pankraz76 mentioned this pull request Jun 23, 2025
[core] add IDE agnostic configuration pmd/pmd#5651
Closed
@Pankraz76

Pankraz76 commented Jun 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

could migrate the .editorconfig as well dedicated, assuming spot it applied on itself, like checkstyle does impose all checks on itself, too.

spotless/.editorconfig

Line 20 in 2cc8c04

ij_java_class_count_to_use_import_on_demand = 999

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iddeepak
gradle test
825273c
Goooler
Goooler reviewed Jun 23, 2025
View reviewed changes
Comment thread plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RemoveWildcardImportsTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@iddeepak
gradle test
e482db2
@Goooler
Goooler requested a review from Copilot June 23, 2025 16:38

This comment was marked as outdated.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iddeepak and others added 5 commits June 23, 2025 22:11
@iddeepak
Update plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaE…
01c93f3
…xtension.java

Co-authored-by: Copilot <[email protected]>
@iddeepak
spotless apply
a434eed
@iddeepak
Merge branch 'remove-wildcard-imports' of github.com:iddeepak/spotles…
3b9b939
…s into remove-wildcard-imports
@iddeepak
spotless apply
4d74803
@iddeepak
spotless apply
7528572
@iddeepak

iddeepak commented Jun 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

could migrate the .editorconfig as well dedicated, assuming spot it applied on itself, like checkstyle does impose all checks on itself, too.

spotless/.editorconfig

Line 20 in 2cc8c04

ij_java_class_count_to_use_import_on_demand = 999

you mean spot checks on .editorconfig something like this

format("editorconfig") { target "spotless/.editorconfig" editorConfig() }
@Pankraz76

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Pankraz76

Pankraz76 commented Jun 23, 2025

Copy link
Copy Markdown

No, sorry—I meant we could remove this config, assuming it's not needed anymore, as Spot will prevent it now. But keeping it wouldn't hurt, as it still helps to avoid potential issues.

If auto-fix were possible, the config would still help prevent problems before fixing them, in the first place, but it wouldn't be strictly necessary anymore.

The next version will go further and deliver actual imports to fully automate this.

A win for the project. Thanks for the good craftsmanship!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iddeepak

iddeepak commented Jun 23, 2025

Copy link
Copy Markdown
Contributor Author

No, sorry—I meant we could remove this config, assuming it's not needed anymore, as Spot will prevent it now. But keeping it wouldn't hurt, as it still helps to avoid potential issues.

If auto-fix were possible, the config would still help prevent problems before fixing them, in the first place, but it wouldn't be strictly necessary anymore.

The next version will go further and deliver actual imports to fully automate this.

A win for the project. Thanks for the good craftsmanship!

Ohh no my bad, I misunderstood it. Now it makes sense. Lets keep that setting in place as an extra safety as of now. Without it, IntelliJ’s default of 5 would collapse to a wildcard on the 6th import, then Spotless would strip that wildcard and force everyone to re-import.

jhult reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Goooler

Goooler commented Jun 24, 2025

Copy link
Copy Markdown
Member

I meant we could remove this config, assuming it's not needed anymore, as Spot will prevent it now.

It could be honored by the IDEA side.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Goooler Goooler changed the title Remove wildcard imports Add support for removing wildcard imports via removeWildcardImports step Jun 24, 2025
Goooler
Goooler approved these changes Jun 24, 2025
View reviewed changes
Comment thread CHANGES.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread plugin-gradle/CHANGES.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread plugin-maven/CHANGES.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Goooler
Apply suggestions from code review
19381b2
@Goooler Goooler changed the title Add support for removing wildcard imports via removeWildcardImports step Support removing wildcard imports via removeWildcardImports step Jun 24, 2025
@Goooler
Goooler merged commit 922f9f1 into diffplug:main Jun 24, 2025
@Pankraz76

Pankraz76 commented Jun 24, 2025

Copy link
Copy Markdown

Thanks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Pankraz76
Pankraz76 reviewed Jun 24, 2025
View reviewed changes

@Pankraz76 Pankraz76 left a comment

Copy link
Copy Markdown

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.

idea on removeObsoletes().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread plugin-gradle/README.md
importOrderFile('eclipse-import-order.txt') // import order file as exported from eclipse

removeUnusedImports()
removeWildcardImports()

@Pankraz76 Pankraz76 Jun 24, 2025

Copy link
Copy Markdown

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.

removeObsoletes()
removeObsoleteInit()
removeObsoleteInitializations()

  • https://github.com/diffplug/spotless/pull/2520/files#r2163362170

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
This was referenced Jun 24, 2025
feat: Disable expandEmptyElements, to avoid empty body warnings #2520
Merged
activate removeWildcardImports() #2526
Merged
@Pankraz76 Pankraz76 mentioned this pull request Jul 1, 2025
Activate removeWildcardImports() in Spotless junit-team/junit-framework#4704
Closed
6 tasks
@nedtwigg

nedtwigg commented Jul 7, 2025

Copy link
Copy Markdown
Member

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

marcusdacoregio, iddeepak, james-hayes-emburse, Pankraz76, and awa-xima reacted with thumbs up emoji
All reactions
  • 👍 5 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tsaglam tsaglam mentioned this pull request Jul 9, 2025
Enable avoidance of wildcard imports for spotless jplag/JPlag#2486
Closed
This was referenced Jul 16, 2025
Bump spotless to 8.0.0 opensearch-project/OpenSearch#18770
Merged
detect and ban wildcard imports in Java apache/lucene#14804
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
+2 more reviewers
@Pankraz76 Pankraz76 Pankraz76 approved these changes
@Goooler Goooler Goooler approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

spotless maven eclipse jdt - How to block import star (*) wildcard? Add remove wildcards imports when formating and ordering imports. Unused wild card imports are not removed

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@iddeepak @Pankraz76 @Goooler @nedtwigg
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.