Skip to content

Add dagger.strictAssistedInjectValidation option to validate @AssistedInject and @AssistedFactory in dependencies. - #5283

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_943392337
Sep 26, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_943392337

Conversation

@copybara-service

Copy link
Copy Markdown

Add dagger.strictAssistedInjectValidation option to validate @AssistedInject and @AssistedFactory in dependencies.

In fastInit mode, consuming @AssistedInject classes and @AssistedFactory interfaces from libraries that did not run Dagger's annotation processor previously
compiled by chance. This occurred because fastInit generates assisted factory implementations inline, and Dagger's component processing accidentally generated
missing _Factory classes for @AssistedInject (a behavior only intended for standard @Inject constructors).

However, in standard compilation mode, this same library configuration fails to compile because Dagger requires the pre-generated classes to exist on the
classpath. This creates an undesirable disparity where code compiles in fastInit mode but fails in standard mode.

This change adds a new compiler option, dagger.strictAssistedInjectValidation. When enabled (-Adagger.strictAssistedInjectValidation=ENABLED), Dagger ensures
parity across all compilation modes by preventing accidental on-the-fly generation in fastInit and validating that pre-generated _Factory and _Impl classes
exist on the classpath. If they are missing, Dagger reports a clear compilation error advising the user to apply the Dagger annotation processor to the library
dependency.

RELNOTES=Added the option -Adagger.strictAssistedInjectValidation=ENABLED to validate that libraries defining @AssistedInject or @AssistedFactory ran the Dagger annotation processor.

…tedInject and @AssistedFactory in dependencies.

In `fastInit` mode, consuming `@AssistedInject` classes and `@AssistedFactory` interfaces from libraries that did not run Dagger's annotation processor previously
compiled by chance. This occurred because `fastInit` generates assisted factory implementations inline, and Dagger's component processing accidentally generated
missing `_Factory` classes for `@AssistedInject` (a behavior only intended for standard `@Inject` constructors).

However, in standard compilation mode, this same library configuration fails to compile because Dagger requires the pre-generated classes to exist on the
classpath. This creates an undesirable disparity where code compiles in `fastInit` mode but fails in standard mode.

This change adds a new compiler option, `dagger.strictAssistedInjectValidation`. When enabled (`-Adagger.strictAssistedInjectValidation=ENABLED`), Dagger ensures
parity across all compilation modes by preventing accidental on-the-fly generation in `fastInit` and validating that pre-generated `_Factory` and `_Impl` classes
exist on the classpath. If they are missing, Dagger reports a clear compilation error advising the user to apply the Dagger annotation processor to the library
dependency.

RELNOTES=Added the option `-Adagger.strictAssistedInjectValidation=ENABLED` to validate that libraries defining `@AssistedInject` or `@AssistedFactory` ran the Dagger annotation processor.
PiperOrigin-RevId: 988595397
@copybara-service
copybara-service Bot merged commit cf791f3 into master Sep 26, 2026
4 checks passed
@copybara-service
copybara-service Bot deleted the test_943392337 branch September 26, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant