It is not very optimal to do it manually, CTRL + ALT + O helps but it’s still manual.
Go to Settings > Editor > General >Auto Import and check the Optimize imports on the fly checkbox.
When you commit, tick the Optimize imports
option on the right. This will become the default until you change it.
Choose the project/module you want to remove unused import from in Project view. Then from Code menu choose Optimize imports and confirm with Run. The imports will be cleaned in whole project/module.
In IntelliJ, select the project you want to optimize imports on, go to Code menu and choose Optimize imports and a small Optimize Imports popup window will appear. On the popup window you need to click on Run button. Or alternatively, on IntelliJ on Mac, you can use a keyboard short cut Option + Command + O
File/Settings/Inpsections/Imports
and change “Unused import” to Error. This marks them more clearly in the Inspections gutter and the Inspection Results panel.
How to remove unused methods in IntelliJ?
@Snicolas Right click on the test result (redundancy declaration-> Unused declaration) and select “Delete safely”.
How do I find unused classes in IntelliJ?
When you commit, tick the Optimize imports
option on the right. This will become the default until you change it.
It is not very optimal to do it manually, CTRL + ALT + O helps but it’s still manual.
Choose the project/module you want to remove unused import from in Project view. Then from Code menu choose Optimize imports and confirm with Run. The imports will be cleaned in whole project/module.
File/Settings/Inpsections/Imports
and change “Unused import” to Error. This marks them more clearly in the Inspections gutter and the Inspection Results panel.
In IntelliJ, select the project you want to optimize imports on, go to Code menu and choose Optimize imports and a small Optimize Imports popup window will appear. On the popup window you need to click on Run button. Or alternatively, on IntelliJ on Mac, you can use a keyboard short cut Option + Command + O
FAQ
How do I get rid of unused imports in entire project?
How do I turn off imports in IntelliJ?
In the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | Code Style | Java | Imports. Make sure that the Use single class import option is enabled.
How do I delete unused variables in IntelliJ?
How do I manage imports in IntelliJ?