0
votes

I have a project that has a build.gradle that looks like the following:

  compile project(':project1')
  compile project(':project2')
  compileOnly(group: 'org.scala-lang', name: 'scala-library', version: '2.10.5')

Let's say it is not easy to identify the exact dependencies that I need in "project1", which is the main reason why we have this "whole project" dependency in the first place. Assuming that project1 also depends on scala-lang but a wildly different version. At runtime, some part of our code depends on this "scala-lang" from project1 dependencies, while some other part of the code depends on the scala-lang I specified via compileOnly().

This is just one example, my actual code depends on many projects and many many more individual libraries. Let's also assume that breaking the monolithic code base into smaller and more manageable components is not doable at this time. What are some great ways to manage dependencies and transitive dependencies in Java gradle project? Thanks!

One way to force using a specific library version is to use resolutionStraegy{force ...} , see docs.gradle.org/current/dsl/… - Daniele
Another way, is to use a "dependencyManagement" mechanism similar to Maven BOM- using either the (spring) gradle-dependency-plugin github.com/spring-gradle-plugins/dependency-management-plugin - Daniele
Or, the main BOM support; see docs.gradle.org/5.0/userguide/… - Daniele