Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to limit Dagger factory generation to specific source sets #727

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Control Dagger factory whitelist directly from plugin
  • Loading branch information
matejdro committed Jul 31, 2023
commit 086f51c714f9416430acc07fb0d5d0b05384fd93
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,23 @@ internal open class AnvilPlugin : KotlinCompilerPluginSupportPlugin {
}
}

val variantWhitelist = variant.variantFilter.generateDaggerFactoriesSourceSetWhitelist.flatMap {sourceSetName ->
val whitelistedVariants = variant.variantFilter
.generateDaggerFactoriesSourceSetWhitelist.map { sourceSetName ->
val sourceSet = variant.kotlinSourceSets.singleOrNull { it.name == sourceSetName }
?: throw GradleException("Unknown variant $sourceSetName. Available variants: " +
"${variant.kotlinSourceSets.joinToString { it.name }}")
"${variant.kotlinSourceSets.joinToString { it.name }}"
)

sourceSet.kotlin.srcDirs
sourceSet
}

val enableDaggerFactoriesInThisVariant = whitelistedVariants.isEmpty() ||
variant.androidSourceSets?.any { androidSourceSet ->
whitelistedVariants.any { whitelistedSourceSet ->
whitelistedSourceSet.name == androidSourceSet.name
}
} == true

return project.provider {
listOf(
FilesSubpluginOption(
Expand All @@ -171,15 +180,13 @@ internal open class AnvilPlugin : KotlinCompilerPluginSupportPlugin {
),
SubpluginOption(
key = "generate-dagger-factories",
lazy { variant.variantFilter.generateDaggerFactories.toString() }
),
SubpluginOption(
key = "generate-dagger-factories-path-whitelist",
lazy { variantWhitelist.joinToString(":") { it.absolutePath } }
lazy { (variant.variantFilter.generateDaggerFactories &&
enableDaggerFactoriesInThisVariant).toString() }
),
SubpluginOption(
key = "generate-dagger-factories-only",
lazy { variant.variantFilter.generateDaggerFactoriesOnly.toString() }
lazy { (variant.variantFilter.generateDaggerFactoriesOnly &&
enableDaggerFactoriesInThisVariant).toString() }
),
SubpluginOption(
key = "disable-component-merging",
Expand Down