Add remove wildcards imports when formating and ordering imports.
See original GitHub issueI have some java classes that have imports with wildcards like : import java.util.*;
I want to replace that with the appropriate import list like
import java.util.List;
I’m using this configuration to format my java code
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<!-- Runs in compile phase to fail fast in case of formatting issues.-->
<id>format java</id>
<phase>compile</phase>
<goals>
<goal>apply</goal>
</goals>
<configuration>
<formats>
<!-- you can define as many formats as you want, each is independent -->
<format>
<!-- define the files to apply to -->
<includes>
<include>src/main/java/**/*.java</include>
<include>src/test/java/**/*.java</include>
</includes>
<indent>
<spaces>true</spaces>
<spacesPerTab>4</spacesPerTab>
</indent>
</format>
</formats>
<java>
<eclipse>
<file>${basedir}/formatter/eclipse-format.xml</file>
</eclipse>
<removeUnusedImports/>
<importOrder>
<file>${basedir}/formatter/eclipse.importorder</file>
</importOrder>
</java>
</configuration>
</execution>
</executions>
</plugin>
I have this import order
#Organize Import Order
#Wed Jul 22 13:29:56 EDT 2020
0=java
1=javax
2=org
3=com
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Auto import | IntelliJ IDEA Documentation - JetBrains
Disable wildcard imports to always import single classes · In the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | Code Style | Java ......
Read more >How to disable wildcard imports in IntelliJ IDEA - Marc Nuri
How to disable wildcard imports in IDEA? ; Settings dialog ( Ctrl+Alt+S ) and navigate to the ; Editor | ; Code Style...
Read more >Essential tools to manage import statements in Eclipse
Adding import statements for missing references and removing ... (Essential); Let Eclipse collapse imports in the same package a wildcard (.
Read more >Java static code analysis: Wildcard imports should not be used
Blindly importing all the classes in a package clutters the class namespace and could lead to conflicts between classes in different packages with...
Read more >How to sort imports in alphabeticall order in Intellij?
2 Answers 2 · go into File > Settings · Go into Editor > Code Style > Java, Imports tab · Delete all...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
fwiw, I added the following
replaceRegexpto remove wildcards while formatting:With the Gradle plugin, you can add a custom step that throws an
Exception. We don’t have a way to do that using the maven syntax.