Subcomponent fields are not explicitly sorted, leading to Gradle build cache misses
See original GitHub issueHere’s a similar issue filed against InflationInject: https://github.com/cashapp/InflationInject/issues/181.
We’ve got the following @Subcomponent
declared in our code:
@ActivityScope
@Subcomponent(modules = [MainActivityModule::class])
interface MainActivityComponent : PasscodeView.Injector {
// other code
@Subcomponent(modules = [ViewModule::class])
interface ViewInjector {
fun inflaterFactory(): InflationInjectFactory
}
}
On CI, Dagger generates the following code for ViewInjector
:
private static final class ViewInjectorImpl implements MainActivityComponent.ViewInjector {
// other code
@SuppressWarnings("unchecked")
private void initialize() {
this.refundPaymentPresenterProvider = ...
this.factoryProvider = ...
this.reportAbusePresenterProvider = ...
this.factoryProvider2 = ...
this.mainTabbedScreensPresenterProvider = ...
this.inAppNotificationPresenterProvider = ...
this.factoryProvider3 = ...
this.activityContactPresenterProvider = ...
this.factoryProvider4 = ...
this.receiptDetailsPresenterProvider = ...
this.factoryProvider5 = ...
this.receiptPresenterProvider = ...
this.factoryProvider6 = ...
}
}
And on one of the dev machines the generated code looks like this:
private static final class ViewInjectorImpl implements MainActivityComponent.ViewInjector {
// other code
@SuppressWarnings("unchecked")
private void initialize() {
this.receiptPresenterProvider = ...
this.factoryProvider = ...
this.receiptDetailsPresenterProvider = ...
this.factoryProvider2 = ...
this.activityContactPresenterProvider = ...
this.factoryProvider3 = ...
this.refundPaymentPresenterProvider = ...
this.factoryProvider4 = ...
this.reportAbusePresenterProvider = ...
this.factoryProvider5 = ...
this.mainTabbedScreensPresenterProvider = ...
this.inAppNotificationPresenterProvider = ...
this.factoryProvider6 = ...
}
}
The difference is that the fields aren’t declared in the same order, and even though this doesn’t have any effect on code correctness (please correct me if I’m wrong here), Gradle’s input comparison will fail leading to a cache miss.
The solution might be to sort entries before generating code, similar to https://github.com/cashapp/InflationInject/pull/182.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Debugging and diagnosing cache misses - Gradle User Manual
Diagnosing the reasons for a cache miss This would mean checking the class names and classloader hashes for the task class itself and...
Read more >Order of elements in generated code #1733 - google/dagger
Unfortunately the order of fields, assignments, etc in generated code ... not explicitly sorted, leading to Gradle build cache misses #3169.
Read more >Diagnosing Build Cache misses with Gradle Enterprise task ...
This tutorial describes how to use Gradle Enterprise build comparison to diagnose and optimize build performance issues due to changed task inputs.
Read more >How to disable gradle's local build cache, but keep remote ...
If you need to troubleshoot the use of the build cache (e.g. unexpected cache misses), run with -Dorg.gradle.caching.debug=true .
Read more >OpenJFX 11 Release details - Gluon
JDK-8284676, TreeTableView loses sort ordering when applied on empty table, controls ... JDK-8220222, build.gradle does not specify clearly the project ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Cool, thanks for the update, and glad it worked out!
I’ve got an update: looks like the original source of the issue was the InflationInject bug that I linked - after merging the fix I don’t see any Gradle cache issues in the code that Dagger generates. Given that our
@Subcomponent
depended on theInflationInjectFactory
, it makes sense that the unstable order of entries in the file was propagated to the subcomponent. I’m gonna close this issue as I believe there’s nothing to be done here on the Dagger side, thanks for taking a look!