For various reasons that another is a very bad idea. First and foremost, because you reach into other projects model. Even just for reading this is a very bad idea.
Besides that, yeah, you only get the declared dependencies, not what it resolves to in the end that way, even if it would work properly, which it does not.
And even if it would work properly you get all dependencies declared on all configurations which is very unlikely what you want, you for example also get dependencies on tools only used during build time and so on.
You probably want instead a configuration that depends on all the subprojects and then using these API to work with the resolution result: Graph Resolution