Spring's need for optional dependencies

Peter Levart peter.levart at gmail.com
Thu Dec 17 16:58:31 UTC 2015


On 12/17/2015 12:03 PM, Stephen Colebourne wrote:
> And here are the threads for Joda projects, which also need optional
> dependencies:
> http://mail.openjdk.java.net/pipermail/jigsaw-dev/2015-December/005462.html
> http://mail.openjdk.java.net/pipermail/jigsaw-dev/2015-December/005638.html
> Note, I do not consider command line flags to be acceptable as a solution.
> Stephen
> On 17 December 2015 at 09:41, Stephane Epardaud <stef at epardaud.fr> wrote:
>> As I already mentioned, we also have the need for this in Ceylon, for
>> the same reasons. Dependencies are required at compile-time but optional
>> at run-time, based on detection: if it's there fine, if not then no problem.

The only problem I see with optional dependencies at runtime is as 

If "requires optional X" semantic was to include the module X in 
configuration if it could be found with module finder (on -modulepath), 
otherwise not, then the established configuration would not only be 
dependent on command-line arguments, but also on the content of module 
directories. If there was a common directory used as a repository for 
various modules, you would not be able to opt-out of using a particular 
module if it was declared as optional dependency and included in the 

So instead of assembling command-line arguments (-addmods ...), you 
would be forced to assemble private module directories for each 
particular configuration.

Contrasting this with what we have now, the classpath: you have to 
declare that you use a particular optional dependency on command line, 
by mentioning it on the -classpath. And when you do that (assemble a 
-classpath command line argument), the configuration does not even check 
that it really is there. If the .jar file isn't there, it is simply ignored.

So I think the safe "requires optional X" semantic would have to be such 
that it acts as two descriptors:

requires X - at compile time

nothing - at runtime (no attempt to find the module and add it to 

You would still have to put -addmods X to command line, but then you 
would have a total control over configuration from command-line only.

Optional dependencies basically then just reduce to a means to have two 
different descriptors: one for compile-time and one for run-time, where 
run-time has a sub-set of requires from compile-time descriptor. It can 
be done now (with separate compilation), but it would be convenient to 
have a single descriptor with two scopes of requires.

Regards, Peter

More information about the jigsaw-dev mailing list