This impsort-maven-plugin
allows you to sort your Java source file's import
statements according to the rules you specify.
To add this plugin to your project, configure the plugin similarly to:
<build>
<plugins>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>1.9.0</version>
<configuration>
<groups>java.,javax.,org.,com.</groups>
<staticGroups>java,*</staticGroups>
<excludes>
<exclude>**/thrift/*.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>sort-imports</id>
<goals>
<goal>sort</goal><!-- runs at process-sources phase by default -->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
and build your project, similarly to (it runs at the process-sources phase by default):
mvn package