How to prevent IntelliJ IDEA from deleting unused packages?

Intellij Idea

Intellij Idea Problem Overview


I'm working with intelliJ and my problem is when I start to import some temporary unused packages into my class file intellij delete those line within a second.

how can I turn off this not so nice feature?

Intellij Idea Solutions


Solution 1 - Intellij Idea

Disable File | Settings | Editor | General | Auto Import | Optimize imports on the fly.

Normally you don't need to add imports manually, IDEA does it for you.

Solution 2 - Intellij Idea

For Scala developers: you can have enabled

Settings > Editor > General > Auto Import > Optimize imports on the fly

but add exclusions into

Settings > Editor > Code Style > Scala > Imports always marked as used:

enter image description here

Solution 3 - Intellij Idea

In Intellij 14 : Settings > Editor > General > Auto Import > Optimize imports on the fly.

Solution 4 - Intellij Idea

(Update) For the Scala developers out there, you can have 1/2 the cake and eat the other 1/2 now: disable the auto-optimize for just scala

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSeyed Vahid HashemiView Question on Stackoverflow
Solution 1 - Intellij IdeaCrazyCoderView Answer on Stackoverflow
Solution 2 - Intellij IdeaSashaView Answer on Stackoverflow
Solution 3 - Intellij IdeamerrickView Answer on Stackoverflow
Solution 4 - Intellij IdeaDilum RanatungaView Answer on Stackoverflow