Aleksandr Kravets
Aleksandr Kravets

Reputation: 5947

Maven, Microservices, (Common) Modules

The problem I encountered is pretty standard: I need to have some common code base between micro-services despite the fact that this approach is discouraged as I've heard. At the moment I have common code as separate module that's built into jar and deployed to local Nexus. Then it's used as standard maven compile dependency. We use CI to build all modules. So when I want to change common code and use it in micro-service outright I can't do it. I must go through "two-stage process" when I first push common module changes, wait until module gets built and receives new version; and only then I can push micro-service code that uses that new version. That's at least awkward, in fact it's very annoying.

Can I use common module as some kind of "source dependency" in maven? What's the proper way to implement this?

Upvotes: 1

Views: 725

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35805

The important question is: Is it ok for the different microservices to use different versions of the common jar?

If yes: You do not need to push changes. You update your common jar and test it separately (as far as possible). While updating a microservice, you can update the dependency (if you want). The microservices then run (possibly) different versions of your common jar.

If no: You can put your jar together with all microservices into one multi-module project, but this means that they all have to be built together every time. You cannot change and build a single one any more. But if they rely on common code in the very same version, they are tightly coupled, so that building only one is probably not a good idea anyway.

Upvotes: 2

Related Questions