Intellij IDEA automatically chain packages together if the intermediate ones are otherwise empty. It is a nice feature in general. However, sometimes you don't want them to be chained, especially when you are in the middle of creating new package structures for your new project. I might have come across the setting for disabling this feature for a certain package, but I can't find it where now. So, does anyone know how to control this feature? Thank you very much.
BTW, in case you need clarification, what I mean by package chaining is as follows. Suppose you have this package structure:
$ tree com
com
└── company
└── project
└── some
└── feature
Since there are really nothing else inside the intermediate folders, Intellij IDEA will automatically display it like
com.company.project.some.feature
in the project explorer, which looks like the packages are chained together.
com.foo.devshorts.model
and then i add com.foo.devshorts.controllers
it'll expand out com.foo.devshorts
.
controllers
after creating com.foo.devshorts.model
, I will have to prefix controller
with com.foo.devshorts
, which is annoying.
Uncheck "Hide Empty Middle Packages" under the Project View settings dropdown:
https://i.stack.imgur.com/nwmFm.png
As another solution of how to create another file in the intermediate package:
https://i.stack.imgur.com/xSYhJ.png
Or you just can right-click on left-sided project tab and pick "Compact Middle Packages"
Just simply uncheck flatten modules, flatten package on right-click on PACKAGE drop-down.
As @Shreyash Choudhary said, uncheck Flatten Package
in Project settings worked for me on v. 2021.3.2.
Success story sharing
Compact Middle Packages
in Idea Ultimate 2018.02Compact Middle Packages
is still the name in IntelliJ Idea Ultimate 2020.3.3