Call Task of Subproject in Subproject?

Hello I have the following structure
| subprojectA
| subprojectB

now I have defined a task in subprojectB how can I call that task in subprojectA?
they do not depend on each other via dependencies, etc.
they are both included in the root project via include ‘subprojectA’, ‘subprojectB’

Oh I think I can just call

run.dependsOn ":worker-service:shadowJar"

is that the right way to do it?