javamodulemodule-info

Java:: Module(s) within module?


Is module(s) within module supported in Java Platform Module System (JPMS)? Is it a good practice?

Let's take the following structure as an example. I did not include the module descriptors (module-info.java) for the outermodule1 and the root module (?) which is named modulewithinmodule.

I find having this nested structure useful for managing my dependencies using Maven modules. The configuration and encapsulation of all the (JPMS) modules with a module descriptor work as expected as well.

For my project to be, according to JPMS, fully modularized, should I include a module descriptor for the modules that do not have one now? If so, what directive (command) should I use (if any) for the inner-modules? If not, then they are considered an unnamed module and consequently, will depend on all the java-base modules (and possibly others) whether they are needed or not and make the application heavier; correct?


Solution

  • Thanks to @Slaw's answers, and a bit more research the following is what I have gathered. Correct me if I am wrong.

    1. The nested JPMS modules are not supported.

    2. The above file structure would not result in any nested JPMS structure, and no unnamed JPMS module exists. The compiler should have access to module paths and Maven takes care of that. Note, however, that Maven modules are nested.

    3. According to here, although the unnamed module requires all other named modules automatically, they are only loaded on demand.