You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if Dagger could support processing Jakarta inject annotations as well as javax inject annotations. That would prevent us from potentially having to write a cross injection system constructor like
Fortunately, they don't share a package and it looks like jakarta pretty much only changed the package name.
Reacted by Jeremy Bensing, Sebastian Stenzel, A248, Jonathan Steele, Filipe Sousa, Steven Sheehy, Hendrik Ebbers, KC, Jiri Daněk, Dmytro Kobza and 5 more
I don't know what Jakarta is , but do you know why it is defining its own jsr330 annotations rather than using the standard javax.inject.* annotations?
@bcorso This is the new home for Java EE! Oracle killed javax.* and the Java EE name and forced Eclipse Jakarta to rename to jakarta.* and Jakarta EE (also applies to javax.servlet et al.)
This is a copyright and Oracle-bullshit issue, there's no way backwards 🤷♂️
Instead of supporting both, javax.injectandjakarta.inject, would switching to solely supporting jakarta.inject be an option? For downstream projects this means s/import javax.inject/import jakarta.inject/g. Nothing particularly difficult, but still technically an API-breaking change.
If this was acceptable, implementing this change wouldn't increase the complexity in Dagger.
Thanks for the idea, but for a large breaking change like that we'd have to support both at the same time for some (long) period of time to let people incrementally migrate.
I just learned from the discussions in this PR, that jakarta.inject before version 2.0.0 still uses the old package name. So in fact this would be no breaking change when simply changing the dependency to jakarta.inject:jakarta.inject-api:1.0.3. These are these consequences:
downstream project
depends only on Dagger
depends on Dagger and javax.inject
uses module path
✅ Can now use reliable Automatic-Module-Name
⚠️ Split package
uses classpath
✅ No change
✅ Classes from both jars are identical by design, classloader may choose arbitrarily
The split package is only a virtual problem, since projects relying on the module path will avoid any such configuration. Nevertheless it should be documented.
It is even possible to have jakarta.inject:jakarta.inject-api:1.0.3 and jakarta.inject:jakarta.inject-api:2.0.0 on the module path at the same time, since the former uses java.inject (sic! as per JEP 200) and the latter jakarta.inject automatic module names.
Just to confirm my previous suggestion: I just replaced javax.inject with jakarta.inject-api version 1.0.3 via dependency management in a multi-module project structure. No changes required. Works flawlessly on both modular and legacy projects.
Can you please consider this as a preliminary solution, until a "real" switch to jakarta namespace can happen eventually?
Just to confirm your goals with this, this is so that you can publish a library with a named module that doesn't rely on the filename for the javax dependency since the jakarta dep provides an automatic module name?
If we switched Dagger's dependency to jakarta 1.0.3 for the javax annotations, I'm concerned this might pose a problem when people start migrating since if you need jakarta 2.0.0 for the jakarta annotations, I think Gradle's dependency resolution will just choose the 2.0.0 version and then the old usages of javax will break. I know you said above it is possible to have both 1.0.3 and 2.0.0 on the classpath and module path, but I feel like them being different versions of the same artifact is going to make that complicated for some build systems.
Just to confirm your goals with this, this is so that you can publish a library with a named module that doesn't rely on the filename for the javax dependency since the jakarta dep provides an automatic module name?
Correct. In fact it has to be exactly 1.0.3. Older versions use a wrong module name, newer versions require you to change your imports.
If we switched Dagger's dependency to jakarta 1.0.3 for the javax annotations, I'm concerned this might pose a problem when people start migrating since if you need jakarta 2.0.0 for the jakarta annotations, I think Gradle's dependency resolution will just choose the 2.0.0 version and then the old usages of javax will break. I know you said above it is possible to have both 1.0.3 and 2.0.0 on the classpath and module path, but I feel like them being different versions of the same artifact is going to make that complicated for some build systems.
You're right, I don't know any build tool that allows having two versions of the same dependency simultaneously... 😔
Having mixes of javax. and jakarta. artifacts is already a reality, and for some people mixes of javax. andjakarta. packages too (to a lesser extent), so having to manage your dependencies to select the appropriate dependency is already something we have to do (I suspect many people live with the mix of artifacts and duplicated classes).
So, we're getting off topic here as the original issue was about the packages, and this should probably be discussed in #2636 instead; but choosing jakarta.inject artifacts would:
be a "breaking" change anyway (could cause duplicate classes in downstream projects, from javax.inject ad jakarta.inject artifacts)
allow publishing artifacts that depend on Dagger and are JPMS modules, without having to manage dependencies to switch javax.inject to jakarta.inject in that project.
My opinion: I think I'd prefer that people manage their dependencies to replace javax.inject with jakarta.inject when they want to publish JPMS modules that depend on Dagger. This would put the burden on those projects and projects that use them, rather than every single project that uses Dagger.
I think I'd prefer that people manage their dependencies to replace javax.inject with jakarta.inject when they want to publish JPMS modules that depend on Dagger.
While dependency management works great for applications (as I have previously suggested), it really isn't ideal for libraries. Since you explicitly mention publishing modules, I assume you have libraries in mind here.
If a library starts to manage its dependencies, the library's dependents will "unmanage" this by simply depending on dagger/javax.inject/jakarta.inject themselves (as long as the configuration is not replicated everywhere downstream), causing even more confusion.
Either way some projects will run into problems. So we're back to the original proposal:
either a breaking change in a major release
or as proposed by OP "support processing Jakarta inject annotations as well as javax inject annotations"
Obviously, the latter is the most flexible, allowing downstream projects to decide what annotations library to depend on.
Hi, same question as @ThomasVitale :-) Is there any news on the subject ?
I have code that is shared between a Spring Boot app and an AWS Lambda. The shared code depends on javax.*. My Spring Boot app uses Spring as DI (obviously) and my AWS Lambda uses Dagger as DI (as Dagger is faster to startup).
I would like to upgrade Spring Boot to version 3. So I nee to migrate the shared code to Jakarta EE 9 (it mandatory when using Spring Boot 3). And you see me coming... If I upgrade the shared code to Jakarta EE 9, I need a Dagger version compatible with it to keep my AWS Lambda working :-)
I'm going to try to add Provider support soon, which should cover all of the symbols for Jakarta. Cutting the dep to javax to fix the JPMS issues will likely take more time though.
I actually have a change ready for the first step of adding our own internal Dagger Provider type. I'm hoping to get it out soon. We ended up not being able to just fix it with dagger.internal.Factory because unsurprisingly a lot of our code references javax.inject.Provider directly and that all needs to be replaced. It also breaks the signature of a lot of our runtime methods, so in order to maintain backwards compatibility, there's extra code to detect and handle different backwards compatibility situations between libraries when we generate code.
Frankly, it's been a huge pain even though it seems like a simple rename, which is why this is taking so long. Also, since this change has the potential to break a lot of things, we're trying to isolate it into its own release which is causing some delays too. Hopefully this first step should be out soon. It won't let you break the javax dependency yet, but once that is out and there aren't hopefully any issues, we should hopefully be able to then release an artifact that has our dagger.internal.Provider only extend the Jakarta version of Provider. Note that even with all that, there's still going to be complications with our SPI and how we're going to break some external plugins if we change the binding keys that have Provider in them to the Jakarta type (e.g. some of our Map<K, Provider<V>> bindings), so there's still something to figure out there too.
@Chang-Eric How can we help? Do you have things that need coding? Testing? I'm very interested in helping the team figure this out. Clarifying "this converts to Jakarta, this does not" has been a pain point for folks I support that are using Jakarta and Dagger 2, so I'm motivated.
I just submitted a change in 75d3cbc to add the new dagger.internal.Provider. This won't change anything with Jakarta deps yet, but it is the next step. Hopefully we'll release this soon, so people can start building with this, and then I'll do a change to allow using the Jakarta version in user code. We'll also have to do a change that will break compatibility across versions because unfortunately some of our factories are generated returning the javax.inject.Provider directly, but hopefully that will only be necessary once we actually try to drop the javax dependency.
I ran a quick test on one of my repos with HEAD-SNAPSHOT and it was fine (as I expected). We don't generally do anything too fancy with Dagger, we don't integrate directly with the Provider classes, and we rarely (if ever?) even share Dagger generated code. I kind of expect this effort to be mostly trivial for us.
We have a small project using Dagger. We also tested the head-snapshot version and it worked fine ! Thank you for the work !
I have a question : I had to replace javax package by jakarta package in my code. That was absolutely expected. But in the generated code by Dagger, in *_Factory classes, I saw that there is style javax import, is it normal ? Is it releated to your last message @Chang-Eric ? I admit I didn't understand everything but you're talking about factories and javax :-)
Any idea if support for Jakarta API's is going to be supported with Dagger? We need to migrate to newer versions of software for security and maintainability reasons, so the problem with Jakarta is starting to become quite a big issue.
Any idea if support for Jakarta API's is going to be supported with Dagger? We need to migrate to newer versions of software for security and maintainability reasons, so the problem with Jakarta is starting to become quite a big issue.
@dnouls My experience is that I was able to update my server (e.g., Netty) to Jakarta, but retain the javax.inject API for use with Dagger. In our case, the two were not coupled together. Are you using anything that would force them to use the same packages?
Any idea if support for Jakarta API's is going to be supported with Dagger?
Jakarta APIs like @jakarta.inject.Inject should currently work except for using jakarta.inject.Provider. I'm currently actually working on that (usually a bit each week as I have time), but am running into lots of issues internally that keep blocking this. Unfortunately I don't have an ETA, but this actually is being worked on. It is just slow going as new issues pop up and I don't always have a lot time to dedicate to it.
Reacted by Sean Gilligan
Reacted by Thomas Broyer, sblommers and Illia Achour
Giving an update as some things have changed since my last update a year ago and we never really gave an update on our new plans.
Over the past months we have been working to support KMP and so this is now actually on our roadmap. We have been migrating to XPoet to support Kotlin generation, but even with that nearing completion, there are still a number of hurdles to cross like issues with nullability, visibility, generic types, and dependencies like our dependency on javax and jakarta. There’s no clear date when this will be done, especially since we’re still working on supporting KSP2 which is in itself a blocker for KMP, but we thought we should update this since we are at least working on it.
It basically means the end of Hilt/Dagger
We’re still here =)
I believe that after Dagger supports KMP, there will naturally be a good choice 😁
Activity
bcorso commentedon Aug 20, 2020
I don't know what Jakarta is , but do you know why it is defining its own jsr330 annotations rather than using the standard
javax.inject.*annotations?Have you tried filing a bug with them to switch?
tbroyer commentedon Aug 20, 2020
@bcorso This is the new home for Java EE! Oracle killed
javax.*and the Java EE name and forced Eclipse Jakarta to rename tojakarta.*and Jakarta EE (also applies tojavax.servletet al.)This is a copyright and Oracle-bullshit issue, there's no way backwards 🤷♂️
bcorso commentedon Aug 20, 2020
Oh... wow. Okay, yeah looks like we'll have to support all of
jakarta.injectthen.twillouer commentedon Dec 10, 2020
Hi, with Jersey 3.0 it will be mandatory I think :)
overheadhunter commentedon Jun 30, 2021
Just a thought:
Instead of supporting both,
javax.injectandjakarta.inject, would switching to solely supportingjakarta.injectbe an option? For downstream projects this meanss/import javax.inject/import jakarta.inject/g. Nothing particularly difficult, but still technically an API-breaking change.If this was acceptable, implementing this change wouldn't increase the complexity in Dagger.
Chang-Eric commentedon Jun 30, 2021
Thanks for the idea, but for a large breaking change like that we'd have to support both at the same time for some (long) period of time to let people incrementally migrate.
overheadhunter commentedon Jul 8, 2021
I just learned from the discussions in this PR, that
jakarta.injectbefore version 2.0.0 still uses the old package name. So in fact this would be no breaking change when simply changing the dependency tojakarta.inject:jakarta.inject-api:1.0.3. These are these consequences:Automatic-Module-NameThe split package is only a virtual problem, since projects relying on the module path will avoid any such configuration. Nevertheless it should be documented.
It is even possible to have
jakarta.inject:jakarta.inject-api:1.0.3andjakarta.inject:jakarta.inject-api:2.0.0on the module path at the same time, since the former usesjava.inject(sic! as per JEP 200) and the latterjakarta.injectautomatic module names.overheadhunter commentedon Jul 18, 2021
Just to confirm my previous suggestion: I just replaced
javax.injectwithjakarta.inject-apiversion 1.0.3 via dependency management in a multi-module project structure. No changes required. Works flawlessly on both modular and legacy projects.Can you please consider this as a preliminary solution, until a "real" switch to jakarta namespace can happen eventually?
Chang-Eric commentedon Jul 19, 2021
Just to confirm your goals with this, this is so that you can publish a library with a named module that doesn't rely on the filename for the javax dependency since the jakarta dep provides an automatic module name?
If we switched Dagger's dependency to jakarta 1.0.3 for the javax annotations, I'm concerned this might pose a problem when people start migrating since if you need jakarta 2.0.0 for the jakarta annotations, I think Gradle's dependency resolution will just choose the 2.0.0 version and then the old usages of javax will break. I know you said above it is possible to have both 1.0.3 and 2.0.0 on the classpath and module path, but I feel like them being different versions of the same artifact is going to make that complicated for some build systems.
overheadhunter commentedon Jul 19, 2021
Correct. In fact it has to be exactly 1.0.3. Older versions use a wrong module name, newer versions require you to change your imports.
You're right, I don't know any build tool that allows having two versions of the same dependency simultaneously... 😔
tbroyer commentedon Jul 20, 2021
Having mixes of
javax.andjakarta.artifacts is already a reality, and for some people mixes ofjavax.andjakarta.packages too (to a lesser extent), so having to manage your dependencies to select the appropriate dependency is already something we have to do (I suspect many people live with the mix of artifacts and duplicated classes).So, we're getting off topic here as the original issue was about the packages, and this should probably be discussed in #2636 instead; but choosing
jakarta.injectartifacts would:javax.injectadjakarta.injectartifacts)javax.injecttojakarta.injectin that project.My opinion: I think I'd prefer that people manage their dependencies to replace
javax.injectwithjakarta.injectwhen they want to publish JPMS modules that depend on Dagger. This would put the burden on those projects and projects that use them, rather than every single project that uses Dagger.overheadhunter commentedon Jul 20, 2021
While dependency management works great for applications (as I have previously suggested), it really isn't ideal for libraries. Since you explicitly mention publishing modules, I assume you have libraries in mind here.
If a library starts to manage its dependencies, the library's dependents will "unmanage" this by simply depending on dagger/javax.inject/jakarta.inject themselves (as long as the configuration is not replicated everywhere downstream), causing even more confusion.
Either way some projects will run into problems. So we're back to the original proposal:
Obviously, the latter is the most flexible, allowing downstream projects to decide what annotations library to depend on.
25 remaining items
r0main commentedon Apr 4, 2023
Hi, same question as @ThomasVitale :-) Is there any news on the subject ?
I have code that is shared between a Spring Boot app and an AWS Lambda. The shared code depends on javax.*. My Spring Boot app uses Spring as DI (obviously) and my AWS Lambda uses Dagger as DI (as Dagger is faster to startup).
I would like to upgrade Spring Boot to version 3. So I nee to migrate the shared code to Jakarta EE 9 (it mandatory when using Spring Boot 3). And you see me coming... If I upgrade the shared code to Jakarta EE 9, I need a Dagger version compatible with it to keep my AWS Lambda working :-)
Thank you in advance for the news :-)
Best regards !
Chang-Eric commentedon Apr 26, 2023
I'm going to try to add
Providersupport soon, which should cover all of the symbols for Jakarta. Cutting the dep to javax to fix the JPMS issues will likely take more time though.m-presnov commentedon Nov 24, 2023
Any news about support
jakarta.inject.Providerindagger-compiler?Chang-Eric commentedon Nov 27, 2023
I actually have a change ready for the first step of adding our own internal Dagger Provider type. I'm hoping to get it out soon. We ended up not being able to just fix it with
dagger.internal.Factorybecause unsurprisingly a lot of our code referencesjavax.inject.Providerdirectly and that all needs to be replaced. It also breaks the signature of a lot of our runtime methods, so in order to maintain backwards compatibility, there's extra code to detect and handle different backwards compatibility situations between libraries when we generate code.Frankly, it's been a huge pain even though it seems like a simple rename, which is why this is taking so long. Also, since this change has the potential to break a lot of things, we're trying to isolate it into its own release which is causing some delays too. Hopefully this first step should be out soon. It won't let you break the javax dependency yet, but once that is out and there aren't hopefully any issues, we should hopefully be able to then release an artifact that has our
dagger.internal.Provideronly extend the Jakarta version of Provider. Note that even with all that, there's still going to be complications with our SPI and how we're going to break some external plugins if we change the binding keys that haveProviderin them to the Jakarta type (e.g. some of ourMap<K, Provider<V>>bindings), so there's still something to figure out there too.jeffalder commentedon Dec 5, 2023
@Chang-Eric How can we help? Do you have things that need coding? Testing? I'm very interested in helping the team figure this out. Clarifying "this converts to Jakarta, this does not" has been a pain point for folks I support that are using Jakarta and Dagger 2, so I'm motivated.
Chang-Eric commentedon Dec 7, 2023
I just submitted a change in 75d3cbc to add the new
dagger.internal.Provider. This won't change anything with Jakarta deps yet, but it is the next step. Hopefully we'll release this soon, so people can start building with this, and then I'll do a change to allow using the Jakarta version in user code. We'll also have to do a change that will break compatibility across versions because unfortunately some of our factories are generated returning thejavax.inject.Providerdirectly, but hopefully that will only be necessary once we actually try to drop the javax dependency.One way you can help is if you want to try out the current change at head to make sure there isn't any issue. https://dagger.dev/dev-guide/versions has info on how to depend on the HEAD-SNAPSHOT.
jeffalder commentedon Dec 13, 2023
I ran a quick test on one of my repos with HEAD-SNAPSHOT and it was fine (as I expected). We don't generally do anything too fancy with Dagger, we don't integrate directly with the
Providerclasses, and we rarely (if ever?) even share Dagger generated code. I kind of expect this effort to be mostly trivial for us.r0main commentedon Dec 15, 2023
Hi,
We have a small project using Dagger. We also tested the head-snapshot version and it worked fine ! Thank you for the work !
I have a question : I had to replace javax package by jakarta package in my code. That was absolutely expected. But in the generated code by Dagger, in *_Factory classes, I saw that there is style javax import, is it normal ? Is it releated to your last message @Chang-Eric ? I admit I didn't understand everything but you're talking about factories and javax :-)
Hope this test can help even if it's small !
dnouls commentedon Mar 26, 2024
Any idea if support for Jakarta API's is going to be supported with Dagger? We need to migrate to newer versions of software for security and maintainability reasons, so the problem with Jakarta is starting to become quite a big issue.
jeffalder commentedon Mar 26, 2024
@dnouls My experience is that I was able to update my server (e.g., Netty) to Jakarta, but retain the javax.inject API for use with Dagger. In our case, the two were not coupled together. Are you using anything that would force them to use the same packages?
Chang-Eric commentedon Mar 27, 2024
Jakarta APIs like
@jakarta.inject.Injectshould currently work except for usingjakarta.inject.Provider. I'm currently actually working on that (usually a bit each week as I have time), but am running into lots of issues internally that keep blocking this. Unfortunately I don't have an ETA, but this actually is being worked on. It is just slow going as new issues pop up and I don't always have a lot time to dedicate to it.Make dagger.internal.Provider extend jakarta.inject.Provider.
Make dagger.internal.Provider extend jakarta.inject.Provider.
Make dagger.internal.Provider extend jakarta.inject.Provider.
Junzz0 commentedon Jul 3, 2025
@Chang-Eric Dagger(Desktop) seems to be able to switch to jakarta.inject, but Hilt still relies on javax.inject
But it's not clear to me if it's a problem with the dagger hilt or androidx hilt.
Similar to #4780
#3916 (comment)
Abandon the migration to jakarta.inject
I believe that after Dagger supports KMP, there will naturally be a good choice 😁