Reputation: 358
How can we remove unused imports present in a java project using a Gradle task
Upvotes: 8
Views: 5519
Reputation: 358
we can use the spotless Gradle task to achieve this:
spotless {
java {
importOrder 'java', 'javax', 'org', 'com', 'com.diffplug', '' // A sequence of package names
removeUnusedImports() // removes any unused imports
eclipse().configFile 'spotless.eclipseformat.xml' // XML file dumped out by the Eclipse formatter
}
}
we can also specify the import order for the project.
for additional information refer: https://github.com/diffplug/spotless
Upvotes: 5