Releases: google/dagger
Dagger 2.48
Dagger 2.48
Dagger/Hilt KSP support
Dagger 2.48 includes the alpha release of the Dagger and Hilt KSP processors.
Instructions for using the Dagger/Hilt KSP processors can be found at https://dagger.dev/dev-guide/ksp.
In order to use Daggerβs KSP processor you will need to:
- Follow the basic setup to migrate Daggerβs processors from
kapt
toksp
(see https://dagger.dev/dev-guide/ksp#setup). - Migrate any Dagger SPI plugins to the new Dagger SPI plugins API (with KSP support) (see https://dagger.dev/dev-guide/ksp#new-dagger-spi-plugin-with-ksp-support).
- Ensure that there are no
kapt
processors that generate classes that need to interact with Dagger (see https://dagger.dev/dev-guide/ksp#interaction-with-javackapt-processors).
If you depend on androidx.hilt:hilt-common
or androidx.hilt:hilt-work
they will need to be updated to at least 1.1.0-alpha01.
Also note that Daggerβs KSP processors are still in the alpha stage. So far weβve focused mainly on trying to ensure correctness rather than optimize performance. Please apply due diligence when enabling ksp
and report any bugs or performance issues at https://github.com/google/dagger/issues. The current list of known issues can be found here.
There are also a few potentially breaking changes included with this release. These changes were made to better support Dagger usage with Kotlin sources, and make the migration from KAPT to KSP more seamless. We donβt expect these changes to affect most users. Please see below for more details.
Breaking changes
The dagger.ignoreProvisionKeyWildcards
is now enabled by default
This may break apps that are providing the same binding with different wildcards, e.g. Foo<Bar>
and Foo<? extends Bar>
.
Fix: See https://dagger.dev/dev-guide/compiler-options#ignore-provision-key-wildcards for suggestions on how to fix this. If fixing is not an immediate option, you can still disable the flag with dagger.ignoreProvisionKeyWildcards=DISABLED
.
@Binds
assignability check
Unlike KAPT, KSP takes nullability into account when checking if a type is assignable to another type. This changes the behavior of Daggerβs @Binds
usage validation such that a type that was assignable in KAPT may no longer be assignable in KSP. For example:
// Incorrect: this compiles successfully in KAPT but the compilation fails in KSP
@Binds fun bind(impl: FooImpl<Bar?>): Foo<Bar>
Fix: To fix this breakage, users should update the parameter or return type in the method such that they are actually assignable when taking nullability into account. For example:
// Correct: this compiles successfully in KAPT and KSP
@Binds fun bind(impl: FooImpl<Bar?>): Foo<Bar?>
Top-level @Module
/ @Inject
classes can no longer be private
Top-level @Module
or @Inject
classes can no longer be private. This was previously allowed purely by accident (rather than being an officially supported feature) due to the way Kotlinβs private classes are represented as package-private in KAPTβs generated java stubs.
Fix: Replace the private
visibility modifier with internal
or public
.
@Binds
and @Provides
methods can no longer be extension functions
Normally when we define an @Provides
/@Binds
function we put the dependencies in the parameter list:
@Module
abstract class BarModule {
@Binds
abstract fun bindsBar(@Marker foo: Foo): Bar
}
However, since the introduction of KAPT, it was also technically possible to define an @Provides
/@Binds
function using an extension function:
@Module
abstract class BarModule {
@Binds
abstract fun @receiver:Marker Foo.bindsBar(): Bar
}
This extension function syntax worked more by coincidence (rather than being an officially supported feature) due to the way extension functions are represented in KAPTβs generated java stubs. After review, weβve decided not to support this feature anymore in KAPT or KSP. See more at #3990.
Fix: Use the traditional parameter approach rather than extension functions.
The use of abstract var
properties are no longer allowed in components
A var
property adds both a getter (aka request) method and a setter (aka injection) method for a binding. However, the setter method typically goes unused since there is rarely a case for needing both methods for a single binding. After discussion within the team, weβve decided to ban abstract var
properties in components.
Fix: Use fun
(or val
) for getter methods, use fun
for setter methods.
Other changes
- Fixed #3995: Allow kotlin source to use java keywords as parameter names in KSP (2c31d66).
- Fixed #3991: Fixed error message when there are multiple
@Inject
+@AssistedInject
constructors (9105ee671). - Fixed #3992: Fixed crash crash when there are multiple
@AssistedInject
+@AssistedInject
constructors (9105ee671.) - Add a better error message when Hilt Gradle Plugin class loader conflicts with KSP's Gradle plugin. (3f7b9b5)
Dagger 2.47
Whatβs new In Dagger
- A new default disabled flag
dagger.ignoreProvisionKeyWildcards
has been added. Enabling this flag will be required to use KSP in a future release. For more information on this flag, see the documentation here: https://dagger.dev/dev-guide/compiler-options#ignore-provision-key-wildcards
Bug Fixes
- Update kotlinx-metadata-jvm to 0.6.2 Fixes #3893. (7b16dfd)
- Disallow private modules in Kotlin sources (already disallowed in Java sources). There is an issue with KAPT where the generated stubs for a private Kotlin module would not be private. To prepare for KSP support where the Kotlin source is read directly, this is fixed to be an error as it should have been. (53fd1a4)
Whatβs new in Hilt
Dagger 2.46.1
Dagger 2.46
Whatβs new In Dagger
Bug Fixes
- Fixed #3701 and #3838. Updated Dagger to kotlinx metadata 0.6.0. (7cf53031)
Dagger 2.45
Dagger 2.45
Whatβs new In Dagger
Bug Fixes
- Fixed an issue where a scoped
@Binds
used in a cycle would cause an NPE on component creation in fastInit mode. (fae46c7) - Fixed #3677. Added a better error message for when
@Multibinds
types incorrectly used framework types likeProvider
. (f5ad2b2) - Fixed an issue where when giving a missing binding error, an available matching binding in another component would not be suggested if the matching binding was otherwise unused. (00d84ba)
Whatβs new in Hilt
Bug Fixes
Dagger 2.44.2
Whatβs new in Dagger
Bug fixes
- Fixes #3633: Updated shading rules to include newly added classes in
androidx.room.compiler
to prevent class version conflicts with user dependency on Room.
Dagger 2.44.1
Whatβs new in Dagger
Bug fixes
- Fixes #3619: Upgrades XProcessing jars to get upstream fix for enums in annotations (which were missing fully qualified name or import in generated code).
Dagger 2.44
Whatβs new In Dagger
Potentially breaking changes
- Fixes #3531: Removed formatting from dagger.android generated source could be a breaking change for anyone relying on golden files for Daggerβs generated code. (d123efd)
Bug Fixes
- Fixes #3522: Avoids pre-validating the nearest enclosing type in the InjectProcessingStep. (1d74d1f)
Whatβs new in Hilt
Potentially breaking changes
- Added
ViewModelLifecycle
. This can be injected in the ViewModelComponent and used to register listeners for whenViewModel#onCleared()
is called. This change also includes a breaking change for anyone who implemented theActivityRetainedLifecycle
interface themselves. This should be rare though as this interface was not meant to be implemented by users. (55aa4c6)
Bug Fixes
Dagger 2.43.2
Whatβs New In Dagger
Bug Fixes
- Fixes #3495: Updates the XProcessing jars, which should again be compatible with java 8. (62b7f45)
- Adds support reading metadata from Kotlin 1.8 by updating kotlin-metadata-jvm to 5.0. (353a50b)
- Fixes an issue where the Hilt Gradle Plugin artifact was being bloated with additional classes causing its size to be way bigger than its suppose to be. (8235beb)
Dagger 2.43.1
Whatβs New In Dagger
Bug Fixes
- Fixes #3480. Replace dependency on
javax.annotation:jsr250-api:1.0
withjavax.annotation:javax.annotation-api:1.3.2
. (e9dc377) - Fixes #3483: Add onPluginEnd to BindingGraphPlugin, which will be called after all BindingGraphPlugins have been visited (3445275)
- Fixes #3476: Fix issue with Dagger generating mismatching parameter names in component inject functions. (90300d9)