3

I am creating one application using microservice architecture. I was wondering if we can manage the same Spring Boot version across all microservices. I just don't want to mention Spring Boot version in pom.xml while creating new microservice. If we can manage Spring Boot version at one location then It will make sure all microservices are using the same Spring Boot version and It will be easy to upgrade it for all microservices.

How to manage it if It is possible?

Is it a good practice?

Sarvesh
  • 551
  • 1
  • 10
  • 25

7 Answers7

6

If you really wanted to do this, you could use Maven to build your separate applications (microservices), using a parent POM and Maven's Dependency Management feature (Dependency Management is not the same as Depdencies) to control which version of Spring Boot to use.

However, you should not strictly require that all the microservices use the same version of Spring Boot. If you do that, and one of the microservices must use a newer version of Spring Boot (because it has a crucial new feature, for example), you are forcing all the microservices to be updated at the same time. One of the key benefits of microservices is that each microservice can be built, updated and deployments upgraded somewhat separately, so you would be depriving your system of that benefit.

Done properly, however, this can give you the best of both worlds.

  • Old microservices can continue to use an old version of the parent POM.
  • New and updated microservies can use a new version of the parent POM.
  • It is easy to see if a microservice uses a (very) old version of the parent POM and so should be updated.
  • The current version of the parent POM can indicate which versions of dependencies you regard as "best practice" to use.

However, do not be tempted to use a multi-module Maven structure, because then you will force the microservices to use the same Spring Boot version, which introduces too much coupling in the building of each microservice.

Raedwald
  • 46,613
  • 43
  • 151
  • 237
3

While it is true that "independence" is an important value in a microservice landscape, this does not mean rampant code duplication is preferred. Choose the lesser of two evils and create a parent project which contains only a pom file (no java code) and let all microservices use this pom as its parent pom. In this parent pom file you can declare all versions of all dependencies using the <dependencyManagement> tag and all versions of the plugins using the <pluginManagement> tag. These tags don't actually add any dependencies or plugins to your actual project, it just declares the versions to use if the project were too actually depend on them.

If you are using the spring-boot-starter pom as your parent already, this can work transitively: your microservices have your parent pom, and your parent pom has the spring boot starter pom as its own parent.

If at some point in the future one microservice needs to diverge from this parent pom for one or more particular dependencies, you can declare new version in that project's pom and those values will be used instead, effectively overwriting what is declared in the parent pom(s), so you don't lose this flexibility.

However, we've been working with the spring boot microservices for two years now and keeping the landscape consistent and easy to upgrade simultaneously has proven to be more valuable to us than having independence.

user1884155
  • 3,616
  • 4
  • 55
  • 108
1

How to manage it if It is possible?

With a Maven/Gradle parent pom that defines all versions and dependencies that microservice projects will inherit.

Is it a good practice?

Yes with a certain measure.
It is good idea because using consistent dependencies versions through a set of projects that you develop/maintain is a good idea.
But it doesn't mean that all of the projects will use at the N instant the same version of the parent pom but ideally they should tend to use the latest version of it in the same way that the last version of your parent pom should tend to use the last stable version of Spring Boot.

davidxxx
  • 125,838
  • 23
  • 214
  • 215
0

For each microservice, they should have their own version. Each microservice should have their own upgrade cycle. If you end up creating a common project detecting spring boot version. Different microservices could not continue to take advantage of newer features in spring as well as other frameworks which may be dependent on particular spring versions

Vikram Patil
  • 628
  • 6
  • 20
0

As an option, and if you use private Maven repository, you can install one version of artifact for all Spring libraries you use (even more you can tag them all as you custom version). Then in all your projects just use this tag in dependencies.

AlexGera
  • 756
  • 9
  • 19
-1

There is no such thing in microservices, You need to know and keep the same version while creating any new microservice.

Narendar Reddy M
  • 1,499
  • 1
  • 11
  • 18
-2

You should use parent/child pom.xml. (pom help doc)

Define a parent pom file, and declare all the versions there (in properties tag). Something like:

<properties>
  <spring.version>5.0.5.RELEASE</spring.version>
  <.....>
</properties>

And, in each of your projects, use that parent pom, and while declaring dependencies, use something like:

<dependency>
  <groupod>xyz</groupid>
  <artifactid>xyz</artifactid>
  <version>${spring.version}</version>
</dependency>

This will help when you want to upgrade set of libraries, you will need to update at only one place, and re-build all of your projects.

Gorav Singal
  • 508
  • 3
  • 11