question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Subcomponent fields are not explicitly sorted, leading to Gradle build cache misses

See original GitHub issue

Here’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:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Chang-Ericcommented, Jan 20, 2022

Cool, thanks for the update, and glad it worked out!

0reactions
Egorandcommented, Jan 20, 2022

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 the InflationInjectFactory, 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found