On 26/10/2024 18:16, PavelTurk wrote:
Hello.

I'm developing a multi-layered JPMS application. Let's say that in the boot layer, I have a car component (composed of several jars) that includes an engine (also made up of several jars). All child layers will interact with the car, but they should not have any access to the engine or its jars (classes). To achieve this, I want to place all jars related to the engine in a child layer, thereby hiding these
jars and their classes from other child layers.

However, I’m concerned that this setup results in the boot layer depending on a child layer, which seems to go against JPMS principles,
where typically child layers depend on or use parent layers.

My question is: does placing the engine in a child layer violate JPMS principles, and what would be the best approach in this situation?

I assume the concern is that engine exports its API to all modules. If car and engine were tightly coupled then engine could export its API to only car.

It would be feasible to have the engine modules in a child layer and uses services but only if the engine API (its interface) is in the boot layer. So think about the engine API in the boot layer as a service and where the implementation is provided by a service provider module in a child layer. The code in car would use ServiceLoader to locate the implementation. Random modules in other child layers that want to use engine will be disappointed as there will be no implementation visible to their use of ServiceLoader.

-Alan

Reply via email to