Skip to content

Guice501

Googler edited this page Mar 23, 2021 · 3 revisions

Guice 5.0.1

Released February, 26th, 2021.

This release contains a bug fix for Guice 5.0.0.

Maven

Guice:

<dependency>
  <groupId>com.google.inject</groupId>
  <artifactId>guice</artifactId>
  <version>5.0.1</version>
</dependency>

Extensions:

<dependency>
  <groupId>com.google.inject.extensions</groupId>
  <artifactId>guice-${extension}</artifactId>
  <version>5.0.1</version>
</dependency>

Downloads

Docs

Changes since Guice 4.2.3

Some highlights:
  • Added Java15 support (updated asm and bug fixes).
  • Removed cglib as a core dependency. (#1359)
  • Improved error messages.
  • Improved support for using Guice with Kotlin.
  • Added a mechanism to restrict who can bind types or annotations, to allow library authors to control their bindings.
  • Removed no-aop build variant.
  • Fixed 'illegal reflective access' warnings.
Details, per core + extensions
Guice Core
  • Removed cglib as a core dependency. Guice now uses ASM directly to generate bytecode at runtime for invoking user code and supporting method interception
    • To disable bytecode generation, use the new -Dguice_bytecode_gen_option=DISABLED flag. When disabled, ASM & AOP-related code will still be linked into Guice, but will not be used.
  • Improved error messages
    • package names in error messages are compressed to make it easier to read
    • errors with the same cause are grouped and reported together
    • common error now links to a wiki page on how to debug and fix the error
    • additional information like parameter names are included when code are compiled with javac -parameters flag
    • rich formatting like bold, color are used when errors are displayed in a supported console (can be disabled with -Dguice_colorize_error_messages=DISABLED flag)
  • Improved support for using Guice with Kotlin
    • Multibinder now binds Set<? extends T> so Kotlin code can inject Set<T> instead of Set<@JvmSuppressWildcards T>
    • MapBinder now binds Map<K, ? extends V> so Kotlin code can inject Map<K, V> instead of Map<K, @JvmSuppressWildcards T>
  • Removed dependency stack tracking API in ProvisionListener.getDependencyChain(commit). See below for a workaround if you rely on this API.
  • Duplicate static @Provides method will be deduped - commit
  • Added @RestrictedBindingSource API to limit who can bind certain types/annotations - documentation.
  • Added Key.withAnnotation() API to create keys of the same type with a different annotation - commit
  • ModuleAnnotatedMethodScanner behavior changes:
    • Forbid installing modules with custom provides methods from a ModuleAnnotatedMethodScanner
    • Issue error when a scanner tries to register another scanner
  • Fixed order-dependent private module scanner inheritance
  • Fixed infinite recursion if OptionalBinder links one key to the same key
  • Updated the Guava and ASM versions
TestLib
  • Added BoundFieldModule.WithPermits to support using restricted binding source with BoundFieldModule.
Multibindings
  • Removed multibinds extension since it has been included as part of Guice core since 4.2 release.
AssistedInject
  • Improve the way AssistedInject invokes factory methods, to avoid triggering illegal reflection warnings. Users may need to newly call FactoryModuleBuilder.withLookups. Guice will log a warning if this is required.
Dagger Adapter

Migrating from 4.2.3

See the JDiff change report for complete details.

Using Multibinding extension

If your project dependent on Guice multibindings extension, simply remove the dependency since it's included as part of Guice core.

Using Guice no-AOP version

If you were using Guice no-aop version, simply switch to the standard version of Guice. Previous versions of Guice with no-aop did not use runtime bytecode generation. Starting with this release runtime bytecode generation is enabled by default and can be disabled by setting -Dguice_bytecode_gen_option=DISABLED.

Migrate away from ProvisionListener.getDependencyChain API

Some use cases can be replaced by inferring the current chain via ThreadLocals in the listener, other use cases can use the static dependency graph.

For example,

 bindListener(Matchers.any(), new MyListener());
 ...
 private static final class MyListener implements ProvisionListener {
   private final ThreadLocal<ArrayDeque<Binding<?>>> bindingStack =
       new ThreadLocal<ArrayDeque<Binding<?>>>() {
         @Override
         protected ArrayDeque<Binding<?>> initialValue() {
           return new ArrayDeque<>();
         }
       };

   @Override
   public <T> void onProvision(ProvisionInvocation<T> invocation) {
     bindingStack.get().push(invocation.getBinding());
     try {
       invocation.provision();
     } finally {
       bindingStack.get().pop();
     }
     // Inspect the binding stack...
   }
 }

In this example the bindingStack thread local will contain a data structure that is very similar to the data returned by ProvisionListener.getDependencyChain. The main differences are that linked keys are not in the stack, but such edges do exist in the static dependency graph, so you could infer some of the missing edges.

Clone this wiki locally