Root package declaration to reduce folder clutter


#1

Since (thankfully) a package declaration doesn’t need to match the directory structure, like in Java, it would be great if there could be a way in IDEA to define, say, a root package which would be picked up by all package declarations. This would mean no “package directive does not match file” warnings and when automatically generating package declarations would take into account the root package. This would mean a lot less directory clutter.

E.g. my package is com.foo.bar.baz.mycompany.api. All the directories until api only exist to define the package structure. If I could put somewhere basePackage = “com.foo.bar.baz.mycompany” then use the “api” folder as the base folder, as it were, it would help with folder clutter. Then when I defined a new class under “api”, instead of making the package “api”, it would prepend the base package value.

It would also solve the problem referenced here: https://youtrack.jetbrains.com/issue/SCL-6875


#2

Adding context information may confuse readers, in my opinion should be useful define a base package directive to reduce directory path.

I explain it.

Define basePackage = "org.example"
Create a file in source root directory using package declaration “org.example” -> OK
Create a file in source root directory without package declaration -> warning, package should be "org.example"
Create a file in “api” directory using package declaration “org.example.api” -> OK
Create a file in “api” directory using package declaration “api” -> warning, package should be “org.example.api”

Pay attention: must be possible associate the basePackage to a specified source set.

Using “src/main/kotlin/org/example/api” directory path is excessive long, but this may be a gradle/maven problem.