Another thread is currently transitioning state from ScheduleTasks to null

Infrastructure

gradle: 7.3.3
android gradle plugin: 7.0.4
kotlin: 1.7.10
Java 11

Build scan

link: Build Scan™ | Gradle Cloud Services

Background:

We have a gradle task of visiting a module dependency and it’s children dependencies, it is used to check module dependency change and remind engineer to modify depend document.

It appear following question after we upgrade gradle 7.X.

Caused by: java.lang.IllegalStateException: Another thread is currently transitioning state from ScheduleTasks to null.
	at org.gradle.internal.build.StateTransitionController.takeOwnership(StateTransitionController.java:281)
	at org.gradle.internal.build.StateTransitionController.transitionIfNotPreviously(StateTransitionController.java:185)
	at org.gradle.initialization.VintageBuildModelController.prepareSettings(VintageBuildModelController.java:89)

I used configuration.getIncoming().getResolutionResult().allDependencies api to traverse children dependencies. It actually works before gradle 7.x, but it would have this problems after upgrading gradle 7.x randomly in CI. If I retry this job one or two times, may be it will be passed.

I have tried to resolve this issue by setting this job task org.gradle.parallel=false, it actually works now.

I wonder the correct resolution for visiting resolved dependency way.
source_code.zip (4.0 KB)