How to replace group when the group name is not known in advance

I have this particular situation where the dependency tree could contain two dependencies with the same artifact name but different groups. For example, in different places in the dependency tree I could have:

com.domain.groupA:artifactName1:1.2.3   # Older version of desired group
....
com.domain.groupA:artifactName1:1.2.4   # Latest version of desired group (desired version)
...
com.domain.groupB:artifactName1:2.3.4   # Undesired group, should be replaced by "Latest version"

The problem is I want to replace all non “groupA” groups with the resolved dependency for com.domain.groupA:artifactName1 (which would be version 1.2.4), but I actually do not know ahead of time the other group names that I will be facing and there could be many of them, so they cannot be excluded by name.

I guess you need something like this, just not checking for group and version, but for artifact name, or artifact name while group is not the desired one: Using Resolution Rules