dependency-analysis-gradle-plugin icon indicating copy to clipboard operation
dependency-analysis-gradle-plugin copied to clipboard

Support the new Configuration Cache

Open Mahoney opened this issue 3 years ago • 22 comments

Is your feature request related to a problem? Please describe. I'd like to enable the new configuration cache:

https://docs.gradle.org/6.7-rc-5/userguide/configuration_cache.html

but it has lots of problems with this plugin.

Describe the solution you'd like It would be nice if there were no errors in this plugin when running gradle --configuration-cache

Additional context Obviously this is just a nice to have, everything works without it; just thought I'd put it on the radar.

Mahoney avatar Oct 13 '20 22:10 Mahoney

I agree and would love to have this plugin support the configuration cache, but at the moment it's impossible. Some of the data the plugin needs to operate is not available in a conf-cache-friendly way. There are open issues on the Gradle issue tracker, but as far as I know, no eta on resolving them.

autonomousapps avatar Oct 13 '20 22:10 autonomousapps

Stacktrace for reference

org.gradle.api.InvalidUserCodeException: Listener registration 'TaskExecutionGraph.addTaskExecutionListener' by org.gradle.execution.taskgraph.DefaultTaskExecutionGraph@167d2e92 is unsupported.
	at org.gradle.configurationcache.initialization.DefaultConfigurationCacheProblemsListener.onBuildScopeListenerRegistration(ConfigurationCacheProblemsListener.kt:90)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.event.DefaultListenerManager$ListenerDetails.dispatch(DefaultListenerManager.java:398)
	at org.gradle.internal.event.DefaultListenerManager$ListenerDetails.dispatch(DefaultListenerManager.java:380)
	at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:61)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch.dispatch(DefaultListenerManager.java:368)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast.dispatch(DefaultListenerManager.java:179)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast.dispatch(DefaultListenerManager.java:153)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy21.onBuildScopeListenerRegistration(Unknown Source)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph.notifyListenerRegistration(DefaultTaskExecutionGraph.java:299)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph.addTaskExecutionListener(DefaultTaskExecutionGraph.java:255)
	at com.autonomousapps.DependencyAnalysisPlugin.apply(DependencyAnalysisPlugin.kt:104)
	at com.autonomousapps.DependencyAnalysisPlugin.apply(DependencyAnalysisPlugin.kt:47)

@autonomousapps could you maybe link the upstream gradle issue?

ZacSweers avatar Jan 09 '21 03:01 ZacSweers

@ZacSweers which version of the plugin are you on? I haven't used a task execution listener for a while.

When I'm at my desk I'll link the issue I was thinking about, but I suspect your issue is different.

autonomousapps avatar Jan 09 '21 04:01 autonomousapps

0.61.0

ZacSweers avatar Jan 09 '21 05:01 ZacSweers

Try 0.70.0?

autonomousapps avatar Jan 10 '21 00:01 autonomousapps

For the record, this is the issue I filed against Gradle that prevents this plugin's execution from being fully conf-cache-ready. Please note that simply applying the plugin shouldn't break other aspects of the build: it's simply that the plugin's tasks will always require a full configuration until Gradle fixes the issue (which they have acknowledged they ought to do).

@ZacSweers it was v0.65.0 that removed that task execution listener.

autonomousapps avatar Jan 11 '21 22:01 autonomousapps

0.70 reports no issues for us 👍

ZacSweers avatar Jan 15 '21 05:01 ZacSweers

FYI, Gradle has told me they plan to make the results of dependency resolution available in a CC-friendly way sometime this year. So maybe by 2022 this plugin will be compatible :upside_down_face:

autonomousapps avatar May 11 '21 01:05 autonomousapps

JFYI, version 0.77, got:

Configuration cache state could not be cached: field 'usedTransitiveComponents$delegate' from type 'com.autonomousapps.tasks.AdvicePerVariantTask': error writing value of type 'kotlin.UnsafeLazyImpl'
Configuration cache state could not be cached: field 'value' from type 'kotlin.InitializedLazyImpl': error writing value of type 'java.util.LinkedHashSet'
> Configuration cache state could not be cached: field 'dependency' from type 'com.autonomousapps.internal.TransitiveComponent': error writing value of type 'com.autonomousapps.advice.Dependency'
  > Configuration cache state could not be cached: field 'group$delegate' from type 'com.autonomousapps.advice.Dependency': error writing value of type 'kotlin.SynchronizedLazyImpl'
    > begin 0, end -1, length 10

dsvoronin avatar Sep 15 '21 18:09 dsvoronin

@dsvoronin that issue could probably be resolved quickly. It probably isn't really worth it for that property to be lazy. If you want to open a PR, I think it's just a one-line change.

In general though, this plugin cannot be CC-compatible until Gradle provides a way to examine the resolved dependency graph in a compliant way.

autonomousapps avatar Sep 15 '21 20:09 autonomousapps

@autonomousapps did you see this PR https://github.com/gradle/gradle/pull/18729? As far as i understand it should help

dsvoronin avatar Oct 22 '21 16:10 dsvoronin

You're on top of things! That just got merged yesterday. It'll be in Gradle 7.4, and may require substantial changes to the plugin. No eta at this time.

autonomousapps avatar Oct 23 '21 19:10 autonomousapps

Is there a way to just disable dependency analysis plugin until I need to use it? I guess I could just comment it out, right?

I just noticed (due to an ADS video that was released yesterday) that configuration cache tool is available in AS and it calls out this plugin. 😄

But I don't really use this plugin all the time, so maybe I can just comment it out. Screen Shot 2021-10-28 at 11 14 26 PM

ColtonIdle avatar Oct 29 '21 03:10 ColtonIdle

The only solution at present is to comment it out. I don't have any plans to make it possible to, e.g., "disable" it. I'd rather just make it compliant as soon as it's practical to do so.

autonomousapps avatar Oct 29 '21 05:10 autonomousapps

Cool. No worries. Just checking. Cheers Tony

ColtonIdle avatar Oct 29 '21 14:10 ColtonIdle

gradle/gradle#18729 won't be in 7.4, it needs more work and is being reverted for now in gradle/gradle#19119.

eskatos avatar Nov 25 '21 08:11 eskatos

Thanks for letting me know, @eskatos!

autonomousapps avatar Nov 25 '21 09:11 autonomousapps

Found two other issues related to configuration cache

Task :XYZ:findDeclaredProcsMain of type com.autonomousapps.tasks.FindDeclaredProcsTask: cannot serialize object of type 'com.autonomousapps.services.InMemoryCache', a subtype of 'org.gradle.api.services.BuildService', as these are not supported with the configuration cache.

Task :XYZ:graphViewMain of type com.autonomousapps.tasks.GraphViewTask: cannot serialize object of type 'org.gradle.api.internal.artifacts.configurations.DefaultConfiguration', a subtype of 'org.gradle.api.artifacts.Configuration', as these are not supported with the configuration cache.

mvegter avatar Feb 19 '22 10:02 mvegter

FYI - Additional to @mvegter issues, I'm also seeing this one using 0.80.0 version and Gradle 7.4:

Task :XYZ:locateDependenciesDebug of type com.autonomousapps.tasks.LocateDependenciesTask: cannot serialize object of type 'org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer', a subtype of 'org.gradle.api.artifacts.ConfigurationContainer', as these are not supported with the configuration cache.

eric-labelle avatar Feb 23 '22 14:02 eric-labelle

https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/pull/680 resolves https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/issues/306#issuecomment-1045985505

https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/issues/306#issuecomment-1048848550 is not an issue since 1.0.

autonomousapps avatar May 27 '22 19:05 autonomousapps

Will release the partial support as 1.2.2.

autonomousapps avatar May 27 '22 22:05 autonomousapps

Ended up releasing as 1.3.0, since there was a new feature as well.

autonomousapps avatar May 28 '22 01:05 autonomousapps

Testing Gradle 8.1 RC1, which promotes the configuration cache to stable:

  • If I run buildHealth with org.gradle.configuration-cache=true in 'gradle.properties', all is well.
  • If I add org.gradle.configuration-cache.problems=warn, buildHealth fails with the following:
Execution failed for task ':di-with-koin:graphViewTest'.
> lateinit property compileClasspath has not been initialized

Reproducer with org.gradle.configuration-cache.problems=warn currently set: https://github.com/sdkotlin/sd-kotlin-talks/tree/gradle-8.1 (specifically, https://github.com/sdkotlin/sd-kotlin-talks/tree/73c97f04b1bbbe361ea6c51ae1886f70e208bfa0).

ianbrandt avatar Mar 21 '23 14:03 ianbrandt

Filed #885 for the issue described above (with reference to the possibly related gradle/gradle#24636).

ianbrandt avatar Apr 04 '23 16:04 ianbrandt

Just tried on one of my projects with version 1.14.1 and the latest one at the moment i.e. 1.20.0 No issues with storing configuration cache but it still does end up discarding it every time

0 problems were found storing the configuration cache.

See the complete report at file:///Users/<username>/buildHealth/<project-name>/build/reports/configuration-cache/c9rypw15z23d3mxbpt39glbci/9vgbv9endq14ao2zoc6mlt1j9/configuration-cache-report.html

BUILD SUCCESSFUL in 11s
145 actionable tasks: 116 executed, 17 from cache, 12 up-to-date

Publishing build scan...

Configuration cache entry discarded.  // <-----------

Curious why it is being discarded even it says 0 problems found storing the cache? Something under the hood? Thanks

vicky17d avatar May 10 '23 19:05 vicky17d

@vicky17d discard happens when a task calls Task.notCompatibleWithConfigurationCache(cause). See also https://github.com/gradle/gradle/issues/24636#issuecomment-1496255070 for more details.

TWiStErRob avatar Jun 13 '23 12:06 TWiStErRob

Another configuration cache related thing with Gradle 8.1.1, there seems to be a lot of file system access at configuration time. For any project I see this in the config cache report: Screenshot 2023-06-22 at 11 13 21 It's not that bad but it adds up to thousands or tens of thousands of inputs that Gradle needs to keep track of in big projects

gabrielittner avatar Jun 22 '23 09:06 gabrielittner

Can somebody tell me if this is still blocked by gradle or is there a way forward? If it is waiting on Gradle has an issue been filed with them? It seems that Gradle 7.5 should have all the necessary features: https://gradle-community.slack.com/archives/C013WEPGQF9/p1688473669175499?thread_ts=1688469548.868469&cid=C013WEPGQF9

NikolayMetchev avatar Jul 04 '23 11:07 NikolayMetchev

I think this is not blocked anymore. Gradle now allows resolution results as task inputs. It's sometimes a bit tedious to figure out how to use it correctly, but it works.

This issue just™️ needs to be done now.

(Hint: I think @autonomousapps would be happy to work on this if someone would sponsor the work 😉)

jjohannes avatar Jul 04 '23 14:07 jjohannes

Thanks @jjohannes Just curious if payment for one feature is an option and what would that cost?

NikolayMetchev avatar Jul 04 '23 14:07 NikolayMetchev