0

If I have 10-15 3rd party dependencies that need to be included in X amount of Gradle projects, what is the best and most efficient way of doing that?

Option 1)

Copy/paste each dependency in each project's build.gradle. Lots of duplication of code.

Option 2)

Create a new project that includes all of these 3rd party dependencies, and replace the 3rd party dependency declarations in each of the projects' build.gradle with a dependency declaration for the new project. Still duplication of code, but much less than Option 1.

Option 3)

Something smarter, if it exists???

  • The best way depends on circumstances and might be a matter of opinion (and thus off topic). Generally the concept of shared versions is called bill-of-materials BOM, and is supported in several ways. If you search for that, you might find what you are looking for. – tkruse Mar 17 '20 at 15:42
  • Related: https://stackoverflow.com/questions/9547170/in-gradle-how-do-i-declare-common-dependencies-in-a-single-place, https://stackoverflow.com/questions/59896971/maven-bom-dependencies-in-gradle, https://stackoverflow.com/questions/55687995/publish-bom-as-pom-xml-using-gradle-plugin-java-platform – tkruse Mar 17 '20 at 15:45
  • Also I assume you mean independent gradle projects, not submodules in a game Multimodule project. If that is what you meant, you should make it explicit in the question, but then your question would likely be a duplicate question. – tkruse Mar 17 '20 at 15:50

1 Answers1

1

Option (2) is what you're looking for.

This is essentially what Spring Boot starters are. For example, the spring-boot-starter-json provides (6) dependencies.

With that said, option (2) can either be:

  1. A submodule/subproject of another project
  2. Dedicated project

For either choice, the library project will need to either be published or included within the final artfiact (fat/uber JAR)

Cisco
  • 20,972
  • 5
  • 38
  • 60