Guice600 (original) (raw)

Guice 6.0.0

Released May 12th, 2023.

Maven

Guice:

com.google.inject guice 6.0.0

Extensions:

com.google.inject.extensions guice-${extension} 6.0.0

Downloads

Docs

Changes since Guice 5.1.0

JEE Jakarta Transition

Guice 6.0 adds support for jakarta.inject, the new namespace for theJSR330 spec (after the javax -> jakarta JEE transition). The following links talk more about the jakarta transition:Jarkata EE blog post,Eclipse Foundation blog post,Jakarta EE Wikipedia article,Oracle blog post

Guice 6.0 is being released alongsideGuice 7.0 and is intended to help users migrate their code to the jakarta namespace. Guice 6.0 continues to fully support the javax.inject namespace while also mostly supporting thejakarta.inject namespace. The only part of Guice 6.0 that doesn't supportjakarta.inject are the bind(..).toProvider methods. Those methods still require javax.inject or com.google.inject Providers.

The Guice 6.0 servlet & persist extensions only support the javax.servlet andjavax.persistence namespaces respectively. If compatibility withjakarta.servlet or jakarta.persistence is required, use Guice 7.0.

Guice 7.0 removes support for javax.inject, javax.servlet andjavax.persistence. Other than the namespace changes, Guice 6.0 & Guice 7.0 are identical.

Guice 6.0 can help with incremental migrations to the jakarta.injectnamespace, by incrementally replacing javax.inject references tojakarta.inject. This works everywhere, except for code where a jakartaProvider is passed to bind(..).toProvider. Any one of the following options can be used to workaround the toProvider issue.

  1. Update to Guice 7.0 instead. Guice 7.0 fully supports jakarta.inject (but does not have support for javax.inject anymore).
  2. Change the provider implementation to instead implementcom.google.inject.Provider (which works in both 6.0 & 7.0).
  3. Change the provider implementations to instead be @Provides methods, or add a wrapper @Provides method that delegates to the actual provider.
  4. Call bind(..).toProvider(Providers.guicify(myJakartaProvider)). Theguicifymethod will adapt a jakarta provider instance to acom.google.inject.Provider. This only works if binding a Provider_instance_. It will not work for binding provider classes, type literals, or keys. If using this approach, it's best to revert the guicify calls when later updating to Guice 7.0, because they otherwise mask the actual provider implementation (which can be accessed through the Guice SPI'sProviderInstanceBinding.getUserSuppliedProvider).

Note that even though Guice 6.0's toProvider methods don't support jakarta providers, Guice 6.0 can inject jakarta.inject.Provider.

Details

See https://github.com/google/guice/compare/5.1.0...6.0.0 for a complete list of changes.

Guice Core

Servlet

Persist

Persist had a number of changes, some of which are backwards incompatible. Notably: injection of EntityManager no longer implicitly starts a unit of work (because this led to leaks). Users can opt-in to the legacy behavior by constructing theJpaPersistModulewith aJpaPersistOptionsthat setssetAutoBeginWorkOnEntityManagerCreationto true.