In the parent project P, i want to set the versions for the dependencies of A, B, C . Not necessarily all the dependencies are used in all the child projects. Say A and B have 2 dependencies d1 and d2 in common, B and C have 3 d3 d4 d5 in common.
I want to list down the versions of d1, d2, d3, d4, d5 in parent build.gradle and in the child projects, i want to just list down the dependencies with the version from parent build.gradle.
I am looking for something similar to dependencymanagement in maven parent projects where we define versions of all the dependencies and in sub-projects we will give the group and artifact information and not the version information.
This is not functionality that is built into Gradle out-of-the-box so you’d have to write some code. In a nutshell you’d expose an extra method on DependencyHandler that looks up the specific version for the provided groupId and artifactId. Alternatively, you might want to also have a look at the Nebula Dependency Recommender plugin. It provides fairly flexible approach to the problem.
Whilst I also prefer @bmuschko’s approach of version variables, there’s also the dependency-management-plugin which is configured in a similar style to maven’s dependencyManagement