• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2023 The Dagger Authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package dagger.hilt.android.plugin
18 
19 import dagger.hilt.processor.internal.optionvalues.GradleProjectType
20 import org.gradle.api.tasks.Input
21 import org.gradle.process.CommandLineArgumentProvider
22 
23 /**
24  * Plugin configured annotation processor options provider.
25  */
26 internal class HiltCommandLineArgumentProvider(
27   @get:Input
28   val forKsp: Boolean,
29   @get:Input
30   val projectType: GradleProjectType,
31   @get:Input
32   val enableAggregatingTask: Boolean,
33   @get:Input
34   val disableCrossCompilationRootValidation: Boolean
35 ): CommandLineArgumentProvider {
36 
37   private val prefix = if (forKsp) "" else "-A"
38 
39   override fun asArguments() = buildMap {
40     // Enable Dagger's fast-init, the best mode for Hilt.
41     put("dagger.fastInit", "enabled")
42     // Disable @AndroidEntryPoint superclass validation.
43     put("dagger.hilt.android.internal.disableAndroidSuperclassValidation", "true")
44     // Report project type for root validation.
45     put("dagger.hilt.android.internal.projectType", projectType.toString())
46 
47     // Disable the aggregating processor if aggregating task is enabled.
48     if (enableAggregatingTask) {
49       put("dagger.hilt.internal.useAggregatingRootProcessor", "false")
50     }
51     // Disable cross compilation root validation.
52     // The plugin option duplicates the processor flag because it is an input of the
53     // aggregating task.
54     if (disableCrossCompilationRootValidation) {
55       put("dagger.hilt.disableCrossCompilationRootValidation", "true")
56     }
57   }.map { (key, value) -> "$prefix$key=$value" }
58 }