I’m currently working on a project with some spring-boot based microservices. Currently every microservice has it’s own layered jar with the default spring boot layer configuration. This already reduces the number of different layers across minor version changes of the same microservice. But the many different microservices add up when needing to push container images to a customer.
However a lot of microservices share large parts of their dependencies. For example all use spring core and spring boot features. Most of them use spring-data-jpa. Some of them make use of a message broker, solr for search or spring-integration. And then there are features that are unique to only one microservice like there is one that needs to generate pdfs or another needs to send emails.
Am I somehow able to share common layers between different microservices? Like there is a layer containing spring-core and spring-boot and their transitive dependencies. And then there is a layer containing spring-data-jpa and it’s transitive dependencies excluding those from the spring-core and spring-boot layer. And so on ..
2
Answers
In case there is a need to make deliverables smaller one can try the following:
provided
so that it’s not being packaged into the final assembly (that will make local development complicated IMHO).cp
option passed to the JVM as an argument that will reference that folder.Things to consider:
There can be multiple options
OPTION 1 Use multi stage Dockerfile?
this way the team can have a common layer which can run at first
though it may force you to have a single build pipeline for all microservices
we can leverage
--target
argument for during the image build phase to reduce steps to stop at a particular stagefor separate base image for spring-data-jpa, broker, etc. This sounds less fruitful
this option will be slow, the second option below is better I believe.
OPTION 2 Create a common(single or multiple) spring (java) based parent pom.xml(s)
NOTE – will update the answer for more ideas for sure