abagshaw
(Andrew Bagshaw)
November 24, 2019, 4:49pm
#1
In my testing:
someConfiguration.getResolvedConfiguration().getResolvedArtifacts();
Only gets resolved artifacts for someConfiguration
and not any of the configurations that someConfiguration
extends from.
In order to get all artifacts from someConfiguration
AND all the configurations it extends from, I have been using:
someConfiguration
.getHierarchy()
.stream()
.map(c -> c.getResolvedConfiguration().getResolvedArtifacts())
.flatMap(set -> set.stream())
.collect(Collectors.toSet());
And this works for my use case. Is this the correct way to go about getting the resolved artifacts from a configuration and all the configurations it extends from? I expected the first approach to do this already…and the documentation is unclear about this.
jendrik
(Jendrik Johannes)
November 27, 2019, 2:31pm
#2
Hi @abagshaw ,
The Configuration
API is “historically grown” and used for different purposes now. What you do is fine for the case you describe.
In Gradle core, the pattern we now use is to use inheritance to “collect” dependency declarations from other configurations that act as “dependency buckets”. Artifacts are only added to “consumable configurations”. See for example the setup in the java-library plugin:
https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph
And this general description of the “three types” of configurations we now have:
https://docs.gradle.org/current/userguide/declaring_dependencies.html#sec:resolvable-consumable-configs
One aspect here is that we only attach aritfacts to configurations if they are “published” (i.e. used/consumed by other projects/modules).
Our of curiosity: What is your use case to use configurations with aritfacts and inheritance?