Sashi yadav
Sashi yadav

Reputation: 358

Remove unused imports from java project using gradle

How can we remove unused imports present in a java project using a Gradle task

Upvotes: 8

Views: 5519

Answers (1)

Sashi yadav
Sashi yadav

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

Related Questions