-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jakarta.inject support #2058
Comments
I don't know what Jakarta is , but do you know why it is defining its own jsr330 annotations rather than using the standard Have you tried filing a bug with them to switch? |
@bcorso This is the new home for Java EE! Oracle killed |
Oh... wow. Okay, yeah looks like we'll have to support all of |
Hi, with Jersey 3.0 it will be mandatory I think :) |
Just a thought: Instead of supporting both, 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
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 |
Just to confirm my previous suggestion: I just replaced 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. |
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... 😔 |
Having mixes of 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
My opinion: I think I'd prefer that people manage their dependencies to replace <dependencies>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger</artifactId>
<version>2.x</version>
<exclusions>
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies> |
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. |
Do we really have to wait? dapper is a dagger clone that uses jakarta.inject and has a module descriptor. |
To gain some traction: So far we basically decided that changing dependencies just now is not an option. So: What needs to be done in order to support both annotations? |
I think we can support both annotations, but possibly an area of concern will be dealing with Note that this will mean Dagger is going to have both dependencies at the same time, not one or the other, and it will be in our runtime dependency. We will also have to be in this position for the foreseeable future. This would let library code avoid a direct dependency on @overheadhunter I've kind of forgotten the context around the issues with the module system and |
No, sadly this would not solve the problem. As long as Still depending on any lib in No idea how these kinds of dependencies works in Bazel, though. In Gradle it would be |
@overheadhunter Like @Chang-Eric says, it's not so simple because generated code and the Dagger runtime both reference |
Probably a good idea to split up the artifacts. In fact it is hard to ignore that Dagger has a strong focus on Android lately (or always?), which adds lots of classes (like Hilt) that are otherwise irrelevant. A little more modularity would certainly be beneficial, however splitting up artifacts deserves its own issue, I guess? |
If we split our artifacts, I think that could cause issues for libraries that use Dagger. Especially if a library has to inject a
Taking a step back, this sounds to me like possibly a Also, to clarify, Hilt should already be separated into its own set of artifacts that do not affect the core Dagger artifacts. If you find a place where this is not the case though, please let us know (though maybe filed as a separate issue). |
@Chang-Eric Can you explain what you mean by "conflict"? My proposal for splitting the artifacts/packages was specifically to allow both dagger and dagger-jakarta to be included at the same time.
This seems to already be happening in practice; main development of Jetty, Jersey, etc. only support
Primarily developer confusion around which one to import. (It also adds an extra very small JAR everywhere.) |
@brettkail-wk Ah, I think I read your suggestion too fast and missed that you were saying to split the packages as well. With that said, I think it could get really complicated. I think for example we'd actually have to fork our code twice, so there'd be a
While this is kind of unfortunate, I feel like there will also likely be a similar confusion with the package/artifact splitting route as well. Making |
I had thought it would be easier to auto-generate the secondary package(s) when building Dagger itself, which would reduce the maintenance burden.
To be sure, this doesn't seem strictly necessary since it seems Dagger could require the injection site to use the same
It seems unfortunate to choose a solution without having some kind of plan for eventually removing Anyway, it's clear you understand my suggestion (even if you prefer another), so I'll go back to watching :-). |
Indeed, this is a problem in
This is not merely about developer confusion. The problem with the 12-year-old
Adding a new dependency to There are further issues related to tools like jlink not being able to calculate the module graph as long as Dagger doesn't include a module description, but these problems are irrelevant as long as the root cause isn't solved. |
@overheadhunter 2.x with |
I see, sounds good! |
@Chang-Eric The generated classes also reference |
@brettkail-wk Yes, we'll update |
…nd Singleton. This does not get rid of the runtime dependency nor does it support Provider yet. Issue #2058. RELNOTES=Support Jakarta versions of Inject, Scope, Qualifier, and Singleton PiperOrigin-RevId: 418678754
…nd Singleton. This does not get rid of the runtime dependency nor does it support Provider yet. Issue #2058. RELNOTES=Support Jakarta versions of Inject, Scope, Qualifier, and Singleton PiperOrigin-RevId: 424427709
Is there any update regarding this issue? |
Unfortunately no. I did part of the changes so that you can use Jakarta types besides |
@Chang-Eric thanks a lot for your answer! |
simple-component is another alternative for those who cannot wait. |
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). Thank you in advance for the news :-) Best regards ! |
I'm going to try to add |
Any news about support |
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 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 |
@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 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. |
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 |
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 ! |
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? |
Jakarta APIs like |
Issue #2058. RELNOTES=Add a jakarta.inject.Provider runtime dependency in preparation for supporting Jakarta Providers PiperOrigin-RevId: 633750268
Issue #2058. RELNOTES=Add a jakarta.inject.Provider runtime dependency in preparation for supporting Jakarta Providers PiperOrigin-RevId: 633750268
Issue #2058. RELNOTES=Add a jakarta.inject.Provider runtime dependency in preparation for supporting Jakarta Providers PiperOrigin-RevId: 634896178
Jakarta is coming to cause headaches for all :)
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
@Inject
@jakarta.inject.Inject
Fortunately, they don't share a package and it looks like jakarta pretty much only changed the package name.
The text was updated successfully, but these errors were encountered: