Skip to content

Commit

Permalink
Update gradle extension setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacSweers committed Aug 3, 2023
1 parent e67fbd1 commit 99658b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public abstract class AnvilExtension @Inject constructor(objects: ObjectFactory)
.convention(false)

/**
* Enables experimental KSP support. This is only useful if using Dagger with KSP and if
* [disableComponentMerging] is set to `false`.
* Enables experimental KSP support in component merging. This is only
* useful if using Dagger with KSP and if [disableComponentMerging] is set to `false`.
*/
public val useKsp: Property<Boolean> = objects.property(Boolean::class.java)
public val enableKspComponentMerging: Property<Boolean> = objects.property(Boolean::class.java)
.convention(false)

@Suppress("PropertyName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ internal open class AnvilPlugin : KotlinCompilerPluginSupportPlugin {
// TODO would be nice if KSP made this a property so these
// could be chained nicely without afterEvaluate
target.afterEvaluate {
if (anvilExtension.useKsp.get()) {
if (anvilExtension.enableKspComponentMerging.get()) {
target.extensions.configure(KspExtension::class.java) { kspExtension ->
kspExtension.excludeProcessor("dagger.internal.codegen.KspComponentProcessor")
}

target.dependencies.add("ksp", "$GROUP:compiler:$VERSION")
}
}
}
Expand Down Expand Up @@ -140,9 +142,11 @@ internal open class AnvilPlugin : KotlinCompilerPluginSupportPlugin {
project.configurations.getByName(variant.compilerPluginClasspathName)
.extendsFrom(getConfiguration(project, variant.name))

disableIncrementalKotlinCompilation(variant)
if (!variant.variantFilter.enableKspComponentMerging) {
disableIncrementalKotlinCompilation(variant)
}

if (!variant.variantFilter.generateDaggerFactoriesOnly) {
if (!variant.variantFilter.generateDaggerFactoriesOnly || !variant.variantFilter.enableKspComponentMerging) {
disableCorrectErrorTypes(variant)

kotlinCompilation.dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public interface VariantFilter : Named {
public var syncGeneratedSources: Boolean

/**
* Enables experimental KSP support. This is only useful if using Dagger with KSP and if
* [disableComponentMerging] is set to `false`.
* Enables experimental KSP support in component merging. This is only
* useful if using Dagger with KSP and if [disableComponentMerging] is set to `false`.
*/
public var useKsp: Boolean
public var enableKspComponentMerging: Boolean
}

internal class CommonFilter(
Expand Down Expand Up @@ -80,8 +80,8 @@ internal class CommonFilter(
}

private var useKspOverride: Boolean? = null
override var useKsp: Boolean
get() = useKspOverride ?: extension.useKsp.get()
override var enableKspComponentMerging: Boolean
get() = useKspOverride ?: extension.enableKspComponentMerging.get()
set(value) {
useKspOverride = value
}
Expand Down

0 comments on commit 99658b3

Please sign in to comment.