Skip to content
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

Replace Guava with standard Java (where possible) #1785

Open
HannesWell opened this issue Dec 29, 2023 · 4 comments
Open

Replace Guava with standard Java (where possible) #1785

HannesWell opened this issue Dec 29, 2023 · 4 comments

Comments

@HannesWell
Copy link
Contributor

HannesWell commented Dec 29, 2023

Guava is a dependency that is often difficult to handle, mainly due to its frequent new major versions.
And in some cases Guice is the main reason why a project (indirectly) requires Guava, for example Maven's core.
At the same time, many of the great features and utilities of Guava have been added to the JDK, directly or indirectly.

Therefore I would like to suggest to replace the usages of Guava with standard Java wherever it is already possible in a simple way with the currently required Java-8.
The ultimate goal would be one day to completely replace Guava with standard Java to get rid of it as Guice dependency.
But since this is a great undertaking and I'm not even absolutely sure it is completely possible with reasonable effort and Java-8, I suggest to start with small steps and see how far we can get. If it is not feasible to replace Guava completely and e.g. features of more recent Java versions are required, it would at least be less work in the future if it is feasible one day.

I can work on this, but would like to know in advance if the Guice team is interested in such changes?

HannesWell added a commit to HannesWell/google.guice that referenced this issue Dec 29, 2023
Additionally use Objects.hashCode() instead of Objects.hash() for single
arguments. This changes the resulting hashCode() but saves the creation
of a singleton array.

Part of google#1785
HannesWell added a commit to HannesWell/google.guice that referenced this issue Dec 29, 2023
Additionally use Objects.hashCode() instead of Objects.hash() for single
arguments. This changes the resulting hashCode() value but saves the
creation of a singleton array.

Part of google#1785
@HannesWell
Copy link
Contributor Author

As a first example I have created #1786.

@HannesWell
Copy link
Contributor Author

One difficulty I already encountered is that currently Guava's Optional are also supported as a backwards compatible alternative for java.util.Optional bindings in RealOptionalBinder. But I think this can be solved with some reflection magic or by refactoring the Guava Optional part into a separate/inner class and catching the NoClassDefFoundErrors if the class is absent at runtime so that Guava can at least become an optional dependency.

@HannesWell
Copy link
Contributor Author

@sameb could you please share your general assessment of this proposal and could have a look at the already existing PRs for this topic?

@lobaorn
Copy link

lobaorn commented Jun 1, 2024

Hey @HannesWell , letting you know since you may be targeting Guice 7.0.0, about the new Micronaut Guice project, that depending on your usecase could be a useful replacement: micronaut-projects/micronaut-guice#9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants