#31215 is a prerequisite for this.
From the Gradle 7.5 release notes:
Tasks may need to access dependency resolution results. For example, built-in tasks like dependencies and dependencyInsight do so in order to provide reporting about resolved artifacts and dependency graphs. Other tasks may produce file outputs based on dependency resolution results. Previously, it was only possible by performing dependency resolution in a task action. However, this resulted in suboptimal performance.
Starting with Gradle 7.5 it is now possible to declare dependency resolution results as task inputs.
This allows writing tasks which consume dependency resolution results. Declaring such inputs instead of doing undeclared dependency resolution in task actions allows Gradle to optimise for build incrementality. Additionally, these new types of task inputs are fully supported by the configuration cache.
You can learn more in the Authoring Tasks user manual chapter and with the dedicated sample.