On 14/04/2020 09:24, Jochen Theodorou wrote:
Hi all,

I am wondering if there is a solution purely in the module-info for this:

* Project requires Library1 and Library2
* SomeLibrary requires SharedApi
* OtherLibrary requires SharedApiImpl

The problem is, that it will not compile because SharedApi and
SharedApiImpl implement the same packages but not the same logic. One is
just an API, while the other is an implementation of the API.
This seems futile without first cleaning up the architectural issues.

How does SharedApi locate the implementation? Is this configurable or does it always assume it's in the same run-time package as itself? If the API and implementation (or default implementation) have to be in the same run-time package then it leads to SharedApi and SharedApiImpl needing to be combined into one module, not two.

Why is OtherLibrary requiring SharedApiImpl? This suggests that SharedApiImpl is more than an implementation, does it have an additional implementation specific API that OtherLibrary make use of?

If you decide to combine the API and default implementation into the one module then it will look something like this:

module api {
    exports api;
    uses spi;
}

The default implementation will be non-public classes in the same package as the public API classes. The `uses spi` is stand in for whatever the service type that some other implementation can provide (assume it is indeed pluggable, why else would they be separated in the first place?).

If you don't want to combine the API and implementation into the same module then you'll have to move the implementation to another package so you have something like the following fully encapsulated implementation:

module impl {
    requires api;
    provides spi with impl;
}

Different run-time packages means they can't use package-privates. If there is an implementation-specific/extension API then impl will need to export that package. There will be presumably be api types in the impl specific API so the requires would change to `requires transitive api`. OtherImpl will `requires impl`.

-Alan

Reply via email to