Skip to content

Commit d0de790

Browse files
trexemDagger Team
authored andcommitted
Throw error while trying to set a dagger flag via annotationProcessor
RELNOTES=Added error while trying to set a dagger flag via annotationProcessor PiperOrigin-RevId: 882008099
1 parent 0f7642b commit d0de790

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

  • java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin

java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -402,18 +402,25 @@ class HiltGradlePlugin @Inject constructor(private val providers: ProviderFactor
402402
}
403403

404404
androidExtension.onAllVariants { variant, _ ->
405-
// Error if the user is trying to set the fastInit flag via build file.
406-
if (
407-
variant.javaCompilation
408-
?.annotationProcessor
409-
?.arguments
410-
?.get()
411-
?.containsKey("dagger.fastInit") ?: false
412-
) {
413-
error(
414-
"[Hilt]: The flag 'dagger.fastInit' can only be set via command line. i.e. " +
415-
"add '-Pdagger.fastInit=enabled' to your command line."
416-
)
405+
val processorArgs =
406+
variant.javaCompilation?.annotationProcessor?.arguments?.get() ?: emptyMap()
407+
// Error if the user is trying to set plugin controlled properties via build file.
408+
processorArgs.keys.forEach { arg ->
409+
when (arg) {
410+
"dagger.hilt.fastInit" ->
411+
error(
412+
"[Hilt]: The flag 'dagger.hilt.fastInit' can only be set via command line. i.e. " +
413+
"add '-Pdagger.hilt.fastInit=enabled' to your command line."
414+
)
415+
"dagger.hilt.android.internal.disableAndroidSuperclassValidation",
416+
"dagger.hilt.android.internal.projectType",
417+
"dagger.hilt.internal.useAggregatingRootProcessor",
418+
"dagger.hilt.disableCrossCompilationRootValidation" ->
419+
error(
420+
"[Hilt]: The flag '$arg' cannot be set via annotation processor options because " +
421+
"it is controlled by the Hilt plugin."
422+
)
423+
}
417424
}
418425
// Pass annotation processor flags via a CommandLineArgumentProvider so that plugin
419426
// options defined in the extension are populated from the user's build file.

0 commit comments

Comments
 (0)