javaspring-bootdockergradlecontainer-image

How to share jar layers between diffrent microservices?


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 ..


Solution

  • In case there is a need to make deliverables smaller one can try the following:

    Things to consider: