How to prevent IntelliJ IDEA from deleting unused packages?
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.
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: