-
Notifications
You must be signed in to change notification settings - Fork 160
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
Centralise the DI code generation logic #3562
Conversation
Add it to `app` and `appnav` modules.
📱 Scan the QR code below to install the build (arm64 only) for this PR. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #3562 +/- ##
========================================
Coverage 82.67% 82.68%
========================================
Files 1732 1732
Lines 40970 40970
Branches 4962 4962
========================================
+ Hits 33873 33874 +1
Misses 5341 5341
+ Partials 1756 1755 -1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Only minor remarks that you may ignore, especially because it's on part that will be updated soon.
You should maybe also update this file: https://github.com/element-hq/element-x-android/blob/develop/tools/templates/files/fileTemplates/Template%20Module%20Feature%20Build%20Gradle%20Impl.kts
anvil(projects.anvilcodegen) | ||
implementation(libs.dagger) | ||
kapt(libs.dagger.compiler) | ||
setupAnvil() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to pass generateDaggerCode = true
and generateDaggerFactoriesUsingAnvil = false
here (because generateDaggerFactories.set(true)
was not present in the current version of the file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think this was a mistake and we were generating the code twice. I removed that and set all the code generation logic in app
and it seems to be working fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks
if (generateDaggerCode) { | ||
applyPluginIfNeeded("org.jetbrains.kotlin.kapt") | ||
// Needed at the top level since dagger code should be generated at a single point for performance | ||
dependencies.add("implementation", libs.dagger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can maybe use the form
dependencies.add("implementation", libs.dagger) | |
dependencies.implementation(libs.dagger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this requires us to use this kind of impot:
import gradle.kotlin.dsl.accessors._719af408c2a6c8acb7cff251b94eadcc.implementation
I think that's quite prone to breaking, a new Gradle version will probably generate a new internal id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I did not have to add such import during my test, but maybe I missed something.
if (project.pluginManager.hasPlugin("io.element.android-compose-library") | ||
|| project.pluginManager.hasPlugin("io.element.android-compose-application")) { | ||
// Annotations to generate DI code for Appyx nodes | ||
dependencies.add("implementation", project.project(":anvilannotations")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can maybe use the form
dependencies.add("implementation", project.project(":anvilannotations")) | |
dependencies.implementation(project.project(":anvilannotations")) |
) { | ||
val libs = the<LibrariesForLibs>() | ||
// Apply plugins and dependencies | ||
applyPluginIfNeeded("com.squareup.anvil") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applyPluginIfNeeded("com.squareup.anvil") | |
applyPluginIfNeeded(libs.plugins.anvil) |
with change on applyPluginIfNeeded
to
private fun Project.applyPluginIfNeeded(plugin: Provider<PluginDependency>) {
val pluginId = plugin.get().pluginId
if (!pluginManager.hasPlugin(pluginId)) {
pluginManager.apply(pluginId)
}
}
applyPluginIfNeeded("com.squareup.anvil") | ||
|
||
if (generateDaggerCode) { | ||
applyPluginIfNeeded("org.jetbrains.kotlin.kapt") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you decide to do the change above in you'll need to change here too to
applyPluginIfNeeded(libs.plugins.kapt)
Quality Gate passedIssues Measures |
Content
Centralise the DI setup in a single
setupAnvil()
function.Motivation and context
Tests
Build the app & check it runs I guess? 😅
Tested devices
Checklist