How to define a new transitive dependency configuration?

Hey. I dug deep however I seem to always keep loosing it at some point in time, e.g. following the “Sharing outputs between projects” guide. Here is what I am trying to do:

I need to model the transitive dependencies between specific artifacts in our project:

  • moduleA has a dependency to moduleB
  • moduleB has a dependency to moduleC

So moduleA has a transitive dependency to moduleC. In this relation, I don’t care about any other (Java related) dependencies (e.g. to dependent libraries / projects defined as implementation dependency).

Essentially I would like to define, in moduleA:

dependencies {
   relatedModule "group:moduleB:1.0.0"
}

And in moduleB:

dependencies {
   relatedModule "group:moduleC:0.5.0"
}

And if I resolve the relatedModule configuration in moduleA, I intend to get the tree resolved:

relatedModule
\--- group:moduleB:1.0.0
     \--- group:moduleC:0.5.0

My idea was to add these relatedModule as a own dependency and scope to the POM.xml, like so:

<dependency>
   <groupId>group</groupId>
   <artifactId>moduleB</artifactId>
   <version>1.0.0</version>
   <scope>related</scope>
</dependency>

This I can easily achieve with modifying the publication and adding the allDependencies from the relatedModule configuration. However I don’t understand how I tell Gradle to only consider “related” dependencies when resolving the configuration and, when resolving the configuration transitively, only be adding dependencies that are “related”. At the moment when I am trying to resolve the relatedModule configuration, I get the whole tree of dependencies, e.g.:

relatedModule
\--- group:moduleB:1.0.0
     \--- com.google.guava:guava:31.0.1-jre
          \--- ...

Is resolved. I have the feeling I am missing a piece of the puzzle. Can I even model such an arbitrary relation between “elements” in Gradle and is there by any chance any example for this?