-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Guice500
Released October, 27th, 2020.
Guice:
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>5.0.0-BETA-1</version>
</dependency>
Extensions:
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-${extension}</artifactId>
<version>5.0.0-BETA-1</version>
</dependency>
This is a beta release of Guice 5.0.0. Please test it and report feedback on the issue track.
- Guice: guice-5.0.0-BETA-1.jar
- Guice extensions are all directly downloadable from this search page. Just click on the "jar" link for the appropriate extension.
- 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.
- 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.
- To disable bytecode generation, use the new
- 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 bindsSet<? extends T>
so Kotlin code can injectSet<T>
instead ofSet<@JvmSuppressWildcards T>
-
MapBinder
now bindsMap<K, ? extends V>
so Kotlin code can injectMap<K, V>
instead ofMap<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
- Added
BoundFieldModule.WithPermits
to support using restricted binding source withBoundFieldModule
.
- Removed multibinds extension since it has been included as part of Guice core since 4.2 release.
- Added
DaggerAdapter.Builder
for setting configuration options onDaggerAdapter
See the JDiff change report for complete details.
If your project dependent on Guice multibindings extension, simply remove the dependency since it's included as part of Guice core.
If you were using Guice no-aop version, simply switch to the standard version of
Guice. Older Guice with no-aop does not use runtime bytecode generation and
starting with this release runtime bytecode generation is enabled by default and
can be disabled by setting -Dguice_bytecode_gen_option=DISABLED
.
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.
-
User's Guide
-
Integration
-
Extensions
-
Internals
-
Releases
-
Community