When supporting different data stores at the same time during development there are multiple spring-boot-starter-data-*
dependencies defined and therefore in the final build JAR.
When in a specific deployment only one of these is required all unrelated auto configurations can be excluded using spring.autoconfigure.exclude=org.springframework...
.
I think this could be a little bit more user friendly by adding a @ConditionalOnProperty("spring.data.MODULE.enabled")
onto the spring data related auto configurations. This would allow disabling specific modules via the well known property mechanism.
Comment From: wilkinsona
Thanks for the suggestion. Generally speaking, we recommend solving this sort of problem at packaging time. Rather than shipping unused dependencies in your final jar file, would it be possible to build different variants of your application, each containing only the dependencies that are needed for its specific deployment?
See also https://github.com/spring-projects/spring-boot/issues/20262 which is somewhat related to this.
Comment From: mvitz
Thanks for the quick reply.
In our current situation we have several stages where the same Docker Image (and therefore final JAR file) must be deployed. Because we are currently migrating from on data store to another one we can switch the implementation at runtime via feature flag and therefore need to ship both dependencies.
I admit that this is a very special case and maybe it's not worth supporting that within Spring Boot.
Comment From: wilkinsona
I admit that this is a very special case and maybe it's not worth supporting that within Spring Boot
I must admit, I'm leaning that way at the moment. Let's see what the rest of the team thinks.
Comment From: wilkinsona
We discussed this today and we've decided not to make any changes here. Thanks anyway for the suggestion.