6 Commits
Author SHA1 Message Date
cpovirk cdf076c99e Annotate toProvider(..) methods to specify that providers can return null.
This doesn't change any Guice behavior; it just lets nullness checkers (like Kotlin and the Checker Framework) allow you to bind to such providers more easily.

Guice's handling of `null` is not entirely principled, and this CL doesn't attempt to "solve" that, nor does it attempt to thoroughly annotate for nullness, let alone enable a nullness checker for the Guice codebase. Rather, it aims only to remove a restriction that I don't think is serving any particular purpose and that no on "intended"; I think it just kind of happened because the Checker Framework treats unannotated code leniently and strictly at different times, and this happens to be one of the strict cases. (We might also have once had the hope of cracking down on injection of `null`?)

The immediate motivation for this CL is https://github.com/google/inject-common/pull/26: Soon, nullness checkers will know that `Providers.of(null)` returns *gasp* a `Provider` that can return `null`. That makes `bind(Foo.class).to(Providers.of(null))` an error. This CL lets those callers continue to compile.

PiperOrigin-RevId: 734755975
2025-03-07 19:00:18 -08:00
Sam Berlin 49b1a33c59 Remove redundant references to javax.{inject,persistence,servlet} and replace the rest with their jakarta variants.
This required upgrading some test dependencies, because the tests need some impls of the APIs which only exist in newer releases.

This also removes the struts2 extension from the maven & bazel build (although it keeps the now-unused source), because struts2 has no release that supports jakarta. For users that want to continue using the struts2 extension, please continue to use the Guice 6.0 release (instead of the 7.0+ line, which will only support the jakarta dependencies).

Fixes #1383.

(I'll cut the 6.0 candidates/releases from before this commit, and if we need to make further 6.0 changes, I'll manually merge those into the 6.0 branch.)

PiperOrigin-RevId: 529504991
2023-05-04 13:50:43 -07:00
Sam Berlin 5eff2eabd4 Add support for jakarta.inject to core Guice.
This does not add support for `toProvider(...)` to instances of `jakarta.inject.Provider` or classes/keys/typeLiterals of type `jakarta.inject.Provider`. See https://github.com/google/guice/issues/1383#issuecomment-1523410855 for details of the plans. The Guice 6.0 release will support `javax.inject` _and_ `jakarta.inject` (excluding `toProvider()` support for `jakarta.inject`), and the Guice 7.0+ release will remove the `javax.inject` references.

Further background on these issues:
 * https://github.com/google/guice/pull/1630
 * https://github.com/google/guice/issues/1679
 * https://github.com/google/guice/issues/1490
 * https://github.com/google/guice/issues/1383

PiperOrigin-RevId: 527349023
2023-04-26 12:55:35 -07:00
Sam Berlin c6b5cdfa94 Add truth's java8 extensions to the external bzl & maven build and update the version we use.
PiperOrigin-RevId: 525459640
2023-04-19 08:49:08 -07:00
Guice Team 86e7ab75b3 Add osgi_jar bazel rule to generate OSGi bundle.
PiperOrigin-RevId: 432496763
2022-03-04 11:42:28 -08:00
Guice Team dea06c1087 Make Guice builds with bazel.
This change only makes it possible to build with bazel and no changes to existing maven setup yet.

PiperOrigin-RevId: 422630465
2022-01-18 13:31:43 -08:00