Use Anvil KSP instead of the Square KAPT one (#3564)
* Use Anvil KSP instead of the Square KAPT one * Fix several configuration cache, lint and test issues * Allow incremental kotlin compilation in the CI * Workaround Robolectric + Compose issue that caused `AppNotIdleException` * Update the `enterprise` commit hash * Update screenshots --------- Co-authored-by: ElementBot <android@element.io>
This commit is contained in:
parent
5fcc80a383
commit
4a43fcb69a
54 changed files with 463 additions and 348 deletions
|
|
@ -16,22 +16,40 @@ import org.gradle.plugin.use.PluginDependency
|
|||
|
||||
/**
|
||||
* Setup Anvil plugin with the given configuration.
|
||||
* @param generateDaggerCode whether to enable general Dagger code generation using Kapt
|
||||
* @param generateDaggerFactoriesUsingAnvil whether to generate Dagger factories using Anvil instead of Kapt
|
||||
* @param generateDaggerCode whether to enable general Dagger code generation using Kapt. `false` by default.
|
||||
* @param generateDaggerFactoriesUsingAnvil whether to generate Dagger factories using Anvil instead of Kapt. `true` by default.
|
||||
* @param componentMergingStrategy how to perform component merging. This is `ComponentMergingStrategy.NONE` by default, which will prevent component merging
|
||||
* from running.
|
||||
*/
|
||||
fun Project.setupAnvil(
|
||||
generateDaggerCode: Boolean = false,
|
||||
generateDaggerFactoriesUsingAnvil: Boolean = true,
|
||||
componentMergingStrategy: ComponentMergingStrategy = ComponentMergingStrategy.NONE,
|
||||
) {
|
||||
val libs = the<LibrariesForLibs>()
|
||||
// Apply plugins and dependencies
|
||||
|
||||
// Add dagger dependency, needed for generated code
|
||||
dependencies.implementation(libs.dagger)
|
||||
|
||||
// Apply Anvil plugin and configure it
|
||||
applyPluginIfNeeded(libs.plugins.anvil)
|
||||
|
||||
project.pluginManager.withPlugin(libs.plugins.anvil.get().pluginId) {
|
||||
// Setup extension
|
||||
extensions.configure(AnvilExtension::class.java) {
|
||||
this.generateDaggerFactories.set(generateDaggerFactoriesUsingAnvil)
|
||||
this.disableComponentMerging.set(componentMergingStrategy == ComponentMergingStrategy.NONE)
|
||||
|
||||
useKsp(
|
||||
contributesAndFactoryGeneration = true,
|
||||
componentMerging = componentMergingStrategy == ComponentMergingStrategy.KSP,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (generateDaggerCode) {
|
||||
applyPluginIfNeeded(libs.plugins.kapt)
|
||||
// Needed at the top level since dagger code should be generated at a single point for performance
|
||||
dependencies.implementation(libs.dagger)
|
||||
dependencies.add("kapt", libs.dagger.compiler)
|
||||
// Needed at the top level since dagger code should be generated at a single point for performance reasons
|
||||
dependencies.add("ksp", libs.dagger.compiler)
|
||||
}
|
||||
|
||||
// These dependencies are only needed for compose library or application modules
|
||||
|
|
@ -40,14 +58,7 @@ fun Project.setupAnvil(
|
|||
// Annotations to generate DI code for Appyx nodes
|
||||
dependencies.implementation(project.project(":anvilannotations"))
|
||||
// Code generator for the annotations above
|
||||
dependencies.add("anvil", project.project(":anvilcodegen"))
|
||||
}
|
||||
|
||||
project.pluginManager.withPlugin(libs.plugins.anvil.get().pluginId) {
|
||||
// Setup extension
|
||||
extensions.configure(AnvilExtension::class.java) {
|
||||
this.generateDaggerFactories.set(generateDaggerFactoriesUsingAnvil)
|
||||
}
|
||||
dependencies.add("ksp", project.project(":anvilcodegen"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -57,3 +68,9 @@ private fun Project.applyPluginIfNeeded(plugin: Provider<PluginDependency>) {
|
|||
pluginManager.apply(pluginId)
|
||||
}
|
||||
}
|
||||
|
||||
enum class ComponentMergingStrategy {
|
||||
NONE,
|
||||
KAPT,
|
||||
KSP
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue