Can't find replacement to Configuration fileCollection(Dependency...)


We are in process of preparing to Gradle 9
We are now working on eliminating the use of Configuration#fileCollection(org.gradle.api.artifacts.Dependency…)

The document says:

Use getIncoming().artifactView(Action) with a componentFilter instead.

But it is not quite the same

conf.getIncoming().artifactView(view -> view.componentFilter(component -> {
                if (component instanceof ModuleComponentIdentifier md) {

                    return md.getGroup().equals(dep.getGroup()) &&
                           md.getVersion().equals(dep.getVersion()) &&

                return false;

Behaves differnetly, is seems - there is not a lot of documnetation - that is select artifacts after resolution, so:

  1. transitive are ignored
  2. if dep was upgradle - due to conflict resolution - it will not be selected.

I hope I was clear :slight_smile:

Can you help me implement it correctly - select artifacts that are resolved for given dependency request ?


According to the last paragraph at Filtered Configuration file and fileCollection methods are deprecated this seems to be intentional and because “This allows for more granular control over which artifacts are selected.”

“more granular” probably means PITA to achieve the same result.

I’m not sure, but I guess you need something like

val ResolvedComponentResult.allComponents: List<ResolvedComponentResult>
    get() {
        return dependencies
            .filterNot { it.isConstraint }
            .flatMap { it.selected.allComponents } + this
val ResolvedComponentResult.allDependencies: List<ComponentIdentifier>
    get() {
        return dependencies
            .filterNot { it.isConstraint }
            .flatMap { it.selected.allDependencies } + id
    .flatMap {
        val wantedComponents = it
            .filter { ( as? ModuleComponentIdentifier)?.let { ( == "wanted-group") && (it.module == "wanted-module") } ?: false }
            .flatMap { it.allDependencies }
            .artifactView { componentFilter { it in wantedComponents } }

to achieve the same result.

From a quick try this seems to produce the intended result.

You should probably open a feature request ticket to get something built-in that behaves like the old method or at least get some documentation about how to do it properly.

Appreciate it, I will try