2

I have:

  • library X with pure interfaces
  • libraries X1, X2, X3, ..., XN which implement interfaces from X
  • SpringBoot project Y built with Gradle 4 and using X

The implementation of X depends on the client we prepare build for.

Options I have in mind:

  • Conditional Gradle build gradle build -Pclient=client1 which will include only one specific implementation
  • Include all implementation as dependencies and have configuration variable which will be discovered runtime and define used implementation.

Now there is a question what are the best practices to follow?

Opal
  • 81,889
  • 28
  • 189
  • 210

1 Answers1

1

Both mechanisms of handling the presented problem are more or less equivalent. I find including only single dependency (namely XN) not only easier to implement using this technology stack but also more reliable:

  • reliable because there's only one particular dependency found on runtime - it's impossible that spring will mess something up with DI
  • easier because if only one implementation is included there's no need for manually handling DI.
  • if only single implementation will be used at runtime - what's the reason for including the else?

Two important things here:

  • provide a detailed log message not only which implementation is included (during build time) but also which one is used (during runtime)
  • it can be done in gradle in two different ways on war level or in dependencies block. Personally I'd go for dependencies block - it make war easier to build.
Opal
  • 81,889
  • 28
  • 189
  • 210
  • Thank you for the answer. I'm still think on that point. Probably, your suggestion (conditional dependency) is better from security point of view, however it's more work from release management point of view - instead of one release -we'll have separate distributions for each client – Siarhei Skavarodkin Sep 26 '17 at 09:19
  • @SiarheiSkavarodkin, yes. Automate that! – Opal Sep 26 '17 at 09:22