Couple `DependencyResult` and downloaded files from `ResolvableDependencies`

Hi,

I’m working to make a Gradle plugin to manipulate dependencies and downloaded files. My question here is: How can I couple DependencyResult and downloaded files from ResolvableDependencies.

final ResolvableDependencies resolvable = configuration.getIncoming();

// Set of downloaded files
final FileCollection fileCollection = resolvable.getFiles();
final Set<File> files = resolvable.getFiles().getFiles();

// DependencyResults
final ResolutionResult results = resolvable.getResolutionResult();
final Set<DependencyResult> dependencies = results.getAllDependencies();

I can get each independent Set of:

  • downloaded files … such as .../.gradle/caches/modules-2/files-2.1/com.example/example-module/0.6.0/f8403641bc17ad3c60250a97ad898514ffd0170a/example-module-0.6.0.jar, …
  • DependencyResults – such as ResolvedDependencyResult that include the component ID like com.example:example-module:0.6.0.

However, I was not sure how I can “map” a downloaded file and a DependencyResult – in other words, I wanted to know which downloaded file (.../example-module-0.6.0.jar) is for which component (com.example:example-module:0.6.0).

I could do a hack with file names (the file example-module-0.6.0.jar should be of com.example:example-module:0.6.0, right?), but it’s uncertain.

I wanted to know a more certain way to couple DependencyResult and downloaded files from ResolvableDependencies.

Thanks.

1 Like

I found ArtifactResolutionQuery.

https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.query.ArtifactResolutionQuery.html

I now can map from Component ID to .pom (MavenPomArtifact), but still not sure how to map into an ordinary .jar file (neither sources nor javadoc)?

Okay, I got one. Self-resolved.

final ResolvableDependencies resolvable = configuration.getIncoming();

final ArtifactCollection collection = resolvable.getArtifacts();
for (final ResolvedArtifactResult result : collection.getArtifacts()) {
    System.out.println(result.getId().getComponentIdentifier());  // => Component ID
    System.out.println(result.getFile());  // => File
}
1 Like