Expose base package + some sub-packages as one module #478
-
Hello, Reading the documentation it states:
However, I like to organise my packages with sub-packages instead of having all my classes in the base package. I'd like the ability to organise them. Is there a way Spring Modulith can be configured to allow the package and all of it's subpackages to be included as a dependency without having to define named interfaces for each of the subpackages? In my situation, there's a module relation from the 'household' module to the 'budgetdefinition' module, both of which are functional modules. Within my 'budgetdefinition' module, I've established a well-organized package structure for different types of classes, enhancing the overall code structure within the module. However, this approach requires me to define NamedInterfaces for each package and add them as allowed packages in my 'household' module. Below, you'll find some output and code snippets for reference. Is there a more elegant solution to address this? NOTE: This is an example project with only a few classes, but in our production code we have many more commands, events, projections, etc in one module. Budgetdefinition Named interfaces: @org.springframework.modulith.ApplicationModule( |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
There is, and – to be blunt – it is not using packages to group types by stereotype. Packages are a means of encapsulation, which is fundamentally subverted if you use them in a way that all important relationships between those elements have to be established across package boundaries. I describe that phenomenon and why it's a bad idea in my Spring Modulith talks (an extended version of this to be found here). Considering this, I think you should see the difficulty you face as messenger that you do something that subverts the original goal, in this case establishing modularity within a codebase. The second hint about that is the fact that you apparently need to make (almost) all code of a module accessible to others. Again, that's the opposite of what we're trying to achieve. One option to get around this problem is to avoid the stereotype packages and rather use, for example, the jMolecules annotations to explicitly mark stereotype types for easier navigation. For 1.2 we are considering introducing the concept of “open modules” that will not hide internals by default. That said, this will be introduced to allow Spring Modulith being used in legacy migrations to mark “modules” that have not been fully modularized. I.e., it's duct tape to avoid the verification from reporting violations that cannot be resolved immediately. It's not something we're going to recommend as general modeling means for new applications that intend to be modularized properly. |
Beta Was this translation helpful? Give feedback.
It's always a bit difficult to evaluate these arrangements with only one, “serving” module in the picture. There are a couple of aspects to the general arrangement, that I find (read: we're moving towards personal opinion here) debatable: