How to replace filtered `getFirstLevel ModuleDependencies()` in ResolvedConfiguration in Gradle 9?

In my Gradle plugin, running on Gradle 8.10.2, I use the following code in order to get the list of first-level dependencies, filtered for ExternalDependencys.

ResolvedConfiguration resolvedCfg = cfg.getResolvedConfiguration();
Set<ResolvedDependency> deps = resolvedCfg.getFirstLevelModuleDependencies(ExternalDependency.class::isInstance);

This works great! But it gives the following deprecation notice:

warning: [deprecation] getFirstLevelModuleDependencies(Spec<? super Dependency>) in ResolvedConfiguration has been deprecated

In the upgrading notices, it is mentioned that one should use the “ArtifactView API” instead. But this will only get me the files associated with the dependency, not the ResolvedDependency object with their metadata.

Please advise! How can I make my code Gradle-9-compatible?

Depends on what you need.
If you need the metadata, not the artifacts, you probably need something like cfg.incoming.resolutionResult.rootComponent that you set as input for your task and where you can then get the information you need at task execution time.