Skip to content

Commit

Permalink
Fix init order in AnvilExtension (#45)
Browse files Browse the repository at this point in the history
These properties are getting set before they're actually initialized
  • Loading branch information
ZacSweers authored Aug 8, 2024
1 parent 07ab80f commit b79251c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
--------------

- **Fix:** Correctly track inputs to KSP command line options so they don't result in incorrect task build cache hits.
- **Fix:** Don't set default AnvilExtension property values until after all properties are initialized.

0.2.1
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ public abstract class AnvilExtension @Inject constructor(
private val providers: ProviderFactory,
) {

init {
val useKspBackend = providers.gradleProperty("com.squareup.anvil.useKspBackend")
.map { it.toBoolean() }
.getOrElse(false)
val useKspComponentMergingBackend = providers.gradleProperty(
"com.squareup.anvil.useKspComponentMergingBackend",
)
.map { it.toBoolean() }
.getOrElse(false)
if (useKspBackend || useKspComponentMergingBackend) {
useKsp(useKspBackend, useKspComponentMergingBackend)
}
}

/**
* Allows you to use Anvil to generate Factory classes that usually the Dagger annotation
* processor would generate for `@Provides` methods, `@Inject` constructors and `@Inject` fields.
Expand Down Expand Up @@ -171,6 +157,20 @@ public abstract class AnvilExtension @Inject constructor(
.orElse(emptySet()),
)

init {
val useKspBackend = providers.gradleProperty("com.squareup.anvil.useKspBackend")
.map { it.toBoolean() }
.getOrElse(false)
val useKspComponentMergingBackend = providers.gradleProperty(
"com.squareup.anvil.useKspComponentMergingBackend",
)
.map { it.toBoolean() }
.getOrElse(false)
if (useKspBackend || useKspComponentMergingBackend) {
useKsp(useKspBackend, useKspComponentMergingBackend)
}
}

/**
* Enables the new [KSP](https://github.com/google/ksp) backends for Anvil. Note that this
* requires the KSP plugin to already be on the buildscript classpath.
Expand Down

0 comments on commit b79251c

Please sign in to comment.