uses is useless ?

Remi Forax forax at
Wed Nov 16 09:48:19 UTC 2016

Hi guys,
sorry for the pun in the title.

Last week end, i've taken a big codebase and try to retrofit it to use jigsaw,
obviously the code has several (two in fact) cyclic dependencies and in both cases, i was able to break those cycles by changing the code to use services.
In one case, i have wanted to write a small code that uses the ServiceLoader like DriverManager.drivers() to expose the service but if i do that,
it's the module that contains that small code that has to declare the directive 'uses' inside its own module-info instead of being the code that effectively uses the service,
which seems wrong to me *.

So i think where missing an API point on ServiceLoader that allow to write a method that will ask for a directive uses on the behalf of the ServiceLoader.

I think it's a good idea to leverage Lookup class here and add a method load(Class, Lookup) that load a service on the behalf to the lookup class and requires the module of the lookup class to declare a directive uses. 


* it's definitevly wrong because when i wanted to use jlink on the code to generate a kind of light version of the application, i was not able to know which modules was using the service to pass them as root modules to jlink.

More information about the jpms-spec-observers mailing list