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.
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.
Using cfg.incoming.resolutionResult.rootComponent actually worked for me! Thanks!
It did come at a price though. When I do need the artifact later on, after working happily with all the metadata, I had to ResolvedConfiguration.getResolvedArtifacts() and match the artifacts to dependencies using their Maven coordinates. It worked, but felt dirty.
Would you know a way to get from a ResolvedDependencyResult to an artifact directly?
No, I have no idea, sorry.
Maybe you need to additionally put in cfg.incoming.artifacts.resolvedArtifacts and then search for the according ones or something like that.