# Recommended ways of (Java) dependency management

**URL:** <https://discuss.gradle.org/t/recommended-ways-of-java-dependency-management/37302>\
**Category:** Help/Discuss\
**Created:** [August 17, 2020, 4:38pm UTC](https://discuss.gradle.org/t/recommended-ways-of-java-dependency-management/37302 "2020-08-17T16:38:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joschi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/joschi/32/2920_2.png) [@joschi](https://discuss.gradle.org/u/joschi)\
**Post date:** [August 17, 2020, 4:38pm UTC](https://discuss.gradle.org/t/recommended-ways-of-java-dependency-management/37302/1 "2020-08-17T16:38:25Z")

</div>

Hi everyone!

I was wondering what the current recommendations for managing JVM (Java) dependencies in multi-project builds are.

For context, we’re talking about a Gradle multi-project build for a Java 11 application with ~100 subprojects and 242 unique external dependencies (dependencies between subprojects not counted).

I’ve found multiple approaches but would like to discuss the advantages and disadvantages.

1. Declare dependencies in a dedicated submodule with the `java-platform` plugin and include the platform in all subprojects. This is the approach I’m currently using
2. Declare dependencies in a map in a Gradle script and refer to them in each subproject `build.gradle` file.  
Example: Kafka
  - [https://github.com/apache/kafka/blob/2.6.0/gradle/dependencies.gradle](https://github.com/apache/kafka/blob/2.6.0/gradle/dependencies.gradle)
  - [https://github.com/apache/kafka/blob/2.6.0/build.gradle#L698](https://github.com/apache/kafka/blob/2.6.0/build.gradle#L698)

3. Declare dependency versions in `gradle.properties` and include them in every subproject.

```gradle
api("org.apache.kafka:kafka-clients:${kafka_version}")
implementation("org.slf4j:slf4j-api:${slf4j_version}")
// ...

```

Which approach are you using What are the advantages or disadvantages you see?

---

<div class="post-metadata">

**Author:** ![joschi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/joschi/32/2920_2.png) [@joschi](https://discuss.gradle.org/u/joschi)\
**Post date:** [September 3, 2020, 3:53pm UTC](https://discuss.gradle.org/t/recommended-ways-of-java-dependency-management/37302/2 "2020-09-03T15:53:20Z")

</div>

Nobody with an opinion on this? 😅

---

<div class="post-metadata">

**Author:** ![knolleCC](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@knolleCC](https://discuss.gradle.org/u/knolleCC)\
**Post date:** [June 6, 2021, 7:01pm UTC](https://discuss.gradle.org/t/recommended-ways-of-java-dependency-management/37302/3 "2021-06-06T19:01:19Z")

</div>

Do you mean all your subprojects share the same dependencies? If I have same configuration in subprojects I usually define it in their parent project like this:

```
subprojects {
    dependencies {
        ...
    }
}

```

You could also create a convention plugin if you have more complex logic, see [Sharing build logic between subprojects Sample](https://docs.gradle.org/current/samples/sample_convention_plugins.html#compiling_convention_plugins)

---

<div class="post-metadata">

**Author:** ![joschi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/joschi/32/2920_2.png) [@joschi](https://discuss.gradle.org/u/joschi)\
**Post date:** [March 13, 2023, 7:41am UTC](https://discuss.gradle.org/t/recommended-ways-of-java-dependency-management/37302/4 "2023-03-13T07:41:30Z")

</div>

> [@knolleCC](#):
>
> Do you mean all your subprojects share the same dependencies?

No, but all subprojects which are using the same dependencies should use them in the same version.

Since tooling support for version catalogs wasn’t good/existent at the time, we went with the platform (BOM) approach.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [March 13, 2023, 11:27am UTC](https://discuss.gradle.org/t/recommended-ways-of-java-dependency-management/37302/5 "2023-03-13T11:27:37Z")

</div>

Platforms and version catalogs are not interchangeable though, they are two different tools that can also be used together.

A version catalog is just a directory of coordinates with versions you can choose from when declaring a dependency, much like just writing the coordinates in the build script itself, or taking it from Gradle properties, or having a holder class in `buildSrc`, just better, standardized, more powerful, and with type-safe accessors in Kotlin DSL.

A platform influences the resolution result, so can for example be used to upgrade transitive dependencies without adding the dependency manually even though you are not using it directly.
