When you have a module A with an optional dependency on B (`requires static 
B`), module B is not resolved from the module path unless `--add-modules B` is 
provided at startup (tested with jigsaw-b151). In [1] this is mentioned as a 
detail, and in fact  it is phrased as a question there. Is this still an open 
question? Because in my mind, expressing an optional dependency *and* having to 
add the module as root module to get it resolved seems a bit over the top (and 
typically you'd also have to add it as dependency in your build tool of choice 
to get it on the module path). 

"If it's on the module path, use it, otherwise, ignore it" is intuitively more 
appealing to me for optional dependencies. It also more closely resembles the 
way things currently work on the classpath with many frameworks. 

For linking, I can see why adding optional modules explicitly is better. Still, 
I think not having to do this at run-time (just like service provider modules 
are resolved at run-time but not at link-time) makes more sense.


[1] http://openjdk.java.net/projects/jigsaw/spec/issues/#CompileTimeDependences 

Reply via email to