google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.45k stars 2.02k forks source link

jpms / modular dagger #2636

Open h908714124 opened 3 years ago

h908714124 commented 3 years ago

I've noticed jlink doesn't work unless every dependency has a module info. I've tried and got this far:

Error: automatic module cannot be used with jlink

It seems dagger doesn't even set Automatic-Module-Name in the MANIFEST. Are there any plans to release a dagger version with module-info.java included?

Because currently it seems like code that uses dagger can't be fully modular, and it looks like that means you won't be able use jlink, to make a custom jdk image of it. Likewise, any library code that uses the dagger annotations will also become a roadblock to modularization. This seems pretty bad. I've just finished adding dagger to my pet command line parser. Will I have to rip it out again? Ugh. Custom runtime images are going to be very important for command line applications, imho. Please respond.

tbroyer commented 3 years ago

Duplicate of #1079

h908714124 commented 3 years ago

@tbroyer sure? The other issue seems to be about adding an "Automatic-Module-Name". But I'm afraid that's not even good enough for jlink. Read the jlink error again: automatic module cannot be used with jlink

Chang-Eric commented 3 years ago

Thanks for the reminder about #1079. I had started on the work to add the automatic module name but never finished submitting it.

For the bigger question of modularizing Dagger, I don't think it is a high priority for us right now when compared to other work we have planned. I'm going to leave this open since it is something we should do, but I can't say when it will be done or that we are looking at this with any urgency right now. Sorry about that =\

h908714124 commented 3 years ago

Hi, thanks for the update. I figured I can use dagger in jbock and still be fully jlink-compatible. This is possible because jbock is an annotation processor itself, so it is not a runtime dependency for its users. I added a module-info to its runtime jar jbock-annotations, which don't use dagger internally, and that's good enough. So it's not a high priority for me anymore.

However, this happy workaround is apparently not available for anything that isn't an annotation processor itself. Dagger cannot be used in a basic jlink-packaged application, like this one. Is that correct?

Another idea: To modularize dagger, it would be enough to add the module descriptor to its runtime jar com.google.dagger:dagger. But this depends on javax.inject, which might be a problem. I found this thread.