We can exclude unwanted classes and packages from ever being suggested by IntelliJ IDEA. See official docs.
It’s a lot easier to develop consistently fast when errors are prevented early.
We know how to fail the build when either an unwanted class or unwanted package has been imported. The build is the best place to implement this kind of safety-net behavior for a couple reasons:
- No setup required for other contributors to the project
- CI will always run the same checks, preventing these errors from making it to test or production environments.
Improving the Developer Experience
Waiting for a build to find out that an unwanted class has been used is frustrating. Fortunately we can set up project-specific or global auto import excludes in Preferences | Editor | General | Auto Import:
This can also be added on-the-fly when importing a new class:
Note There is not currently a plugin that can sync the Checkstyle IllegalImport rule and IntelliJ import exclusions, so watch for these getting out of sync.