Java Magazine, July/August 2018
ORACLE COM JAVAMAGAZINE JULY AUGUST 2018 62 libraries optional dependencies with requires static and dependencies that are exposed to modules requiring your library with requires transitive One option is to depend on automatic modules As I implied when discussing automatic modules it is technically feasible and generally acceptable to depend on nonmodular JAR files so not all of your dependencies need to be modularized for you to modularize your library But be aware that it is extremely careless to require nonmodular JAR files that do not define an automatic module name As pointed out earlier you will expose your users to serious problems if you do that so please dont Consequently you should not publish modular JAR files for your library unless all of your dependencies are either a module or at least define their automatic module name with a manifest entry In fact Maven explicitly warns that you should not publish the artifact if you require a module by its filename I would even go a step further and implore you to check all of your transitive dependencies as well none of them should be Be aware that it is extremely careless to require nonmodular JAR files that do not define an automatic module name required by their filename Handling split packages Another consideration is how to handle split packages Once you start treating dependencies as modules the module system exposes them to more checks which they might fail One example is that some JAR files split packages This refers to a situation in which a package say org lib and two diferent JARs each have a type in that package say org lib Foo in foo jar and org lib Bar in bar jar The module system does not allow that and complains loudly when these JARs end up on the module path Although there are ways to make such a configuration work look up patch module if you need to they require extensive build tool configuration which your users would have to repeat My recommendation is not to put that task onto them Therefore if your dependencies split packages work with them to fix the problem before publishing your project as a module Exporting packages The next step after naming your module and declaring your dependencies is to define your public API The technical aspect is simple just name in an exports directive all
You must have JavaScript enabled to view digital editions.