module resource loading - opens {package} when {package} only holds resources
Rob Bygrave
robin.bygrave at gmail.com
Mon Sep 20 22:15:19 UTC 2021
*> is that you expect code outside of your module to locate these resources*
That's right, the external module reading the resources is not application
specific but a library (its job is to "run database migrations" - open
source, published to maven central etc).
The background is that I have an open source library - Ebean ORM. It is
made up of around 20 modules. It needs to support Java 8 until next march
so it's using multi-version jars to support the module-info. With this
issue resolved to my satisfaction I can merge in the PR that changes it
from using automatic module name to module-info via multi-version jars
(thanks to the moditech plugin).
In case it's interesting, one thing that I hit when migrating to
module-info was that a number of the modules are only used in maven test
scope - as such they don't get a *requires* clause in
src/main/java/module-info. Currently when running tests via maven,
surefire, junit5 there is an unnamed module created for testing purposes
that is patched and adds the main module. Currently these maven test scope
only modules are getting treated as unnamed when running tests and so at
this point can't be referenced in an *exports to* clause of another module.
The net result is that I have some *exports* clauses that ideally
would be *exports
to *but can't at this stage. There might be a detail I am missing but this
is ok and probably isn't a common case.
Thanks again for the help.
Cheers, Rob.
On Mon, 20 Sept 2021 at 22:26, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> On 20/09/2021 11:13, Rob Bygrave wrote:
>
> Well ok, silly me really because I think it is now clear that the "proper
> answer" is that the module really needs to open the subdirectories.
>
> opens dbmigration.postgres;opens dbmigration.mysql;
>
>
> So thanks and apologies Alan. It's all making sense to me now,
> unfortunately I got muddled by that error.
>
> np, but I assume the only reason you open these packages is that you
> expect code outside of your module to locate these resources. If the only
> code that locates the resources is in your module then there should be no
> need to open them.
>
> -Alan
>
More information about the jigsaw-dev
mailing list