2

There are 2 ways to manage versions in multi-project solutions, e.g. Java project with microservices:

Dependency management

In parent pom.xml you define a long list of depencies used across child projects

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
      <version>3.0.1</version>
    </dependency>
  </dependencies>
</dependencyManagement>

and in child pom.xml you just don't specify versions

<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
  </dependency>
</dependencies>

Version placeholders

In parent pom.xml you define properties like

<properties>
  <driver.version>4.9.0-scylla-1</driver.version>
  <spring-boot.version>3.0.1</spring-boot.version>
  <spring-cloud.version>2022.0</spring-cloud.version>
  <lombok.version>1.18.24</lombok.version>
</properties>

then in child pom.xml you must specify version in a way

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-security</artifactId>
  <version>${spring-boot.version}</version>
</dependency>

Which is the preferred way to keep dependency versions consistent in a microservice environment? What are pros and cons of these two ways? The second way seems more elastic because each of child projects may select other version of dependency and you may build project with another version of some dependency from commandline.

Politechniczny
  • 453
  • 3
  • 13
  • And which approach is better when preparing project to run in Kubernetes and for CI/CD by Jenkins or it doesn't matter? – Politechniczny Jan 19 '23 at 17:23
  • The best way is to define the BOM of the spring boot project in your project root (spring-boot-dependencies) which defines all the needed versions of dependencies for spring boot like `spring-boot-starter-security`... or `spring-boot-starter-actuator` ..I only would override the versions of other deps only in case there is a real need for that... I would keep the parent leading way of defining the versions for the childs. That gives the opportunity to change on the child if needed...If that is also going into k8s it doesn't change anything.. from my point of view. – khmarbaise Jan 19 '23 at 18:22

0 Answers0