Chicken and egg problem when depending on artifact configuration

Hello. I’m writing a “dist” task that aggregates various archives produced by (some) subprojects via “distArchives” configuration. In my main project I have:

distFiles(project(mapOf("path" to ":some-subproject-1", "configuration" to "distArchives")))
distFiles(project(mapOf("path" to ":some-subproject-2", "configuration" to "distArchives")))

Unfortunately this means I have to manually specify these subproject dependencies.

Is there any way to somehow automatically add dependencies only to applicable subprojects (i.e. the ones providing “distArchives” configuration), or to add it to all subprojects but somehow make it optional? Obviously inspecting subprojects’ configuration when declaring dependency fails, because it’s empty yet.