When I’ve needed to do things like this in the past, I was recommended to use dependency transforms:
https://docs.gradle.org/current/userguide/artifact_transforms.html
The basic idea was something like put an attribute on all of the dependencies in a configuration, create another configuration that inherits from the first using a different attribute, and then hook up a transform that mapped the first attribute to the second. In this way, you don’t force any dependency resolution or transforms until you actually need them.
It’s been over a year since I was playing with this, so my memory/description are probably a little rough, but hopefully this gets you pointed in the right direction.