Skip to content

Add remove wildcards imports when formating and ordering imports. #649

@survivant

Description

@survivant

I 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions