What is the best way to exclude a transitively depended on project

We have a multi-project build with sub-project X that transitively depends on sub-projects A, B and C. There is another sub-project Y that depends on X. Overall the graph is as follows:

Y -> X -> A, B, C

The problem is that for certain reasons project Y needs, to exclude the transitive dependency on A (i.e. the resolved default config of Y should contain only X, B, C). Typically we would do this with something like this in the project Y build:

dependencies {
   compile project(':X'), { exclude project: ':A' }
}

Except it does not work. The exclude notation relies on group and module.

I tried to use the project group and name, but that didn’t seem to work.

Then I tried to hack the model by manually removing the project from the resolved configuration, but that turned out to be too deep of a rabit hole.

Am I missing anything obvious (short from reorganizing the actual codebase)?

This should work. Just remember that project ‘name’ and ‘path’ are two separate things. So given a project with a path ‘:libs:foo’ the name is simply ‘foo’.