3

I have a piece of code that is an adapter to other solutions (eg: A, B, C). User choose which solution (only one) they will use (via this adapter) in their project. Obviously, I still need to compile my code with A, B, C dependencies. But I don't want to have compile dependency neither on A, B, C - if user, for example, chooses solution A he does not need to include B or C.

Should I declare A,B,C dependency in my POM as:

  1. provided
  2. provided, but optional
  3. just remove them from POM

In other words: does provided means that users MUST provide implementation in their runtime?

Thanx!

EDIT: similar to this question

Community
  • 1
  • 1
igr
  • 10,199
  • 13
  • 65
  • 111

2 Answers2

2

It should be provided - optional.

See linked question for an answer.

igr
  • 10,199
  • 13
  • 65
  • 111
0

You should use provided. Presumably they're implementing an interface you have in common (either yours or a third party). You compile against the interface, and at runtime, somehow, they provide the implementation.

Software Engineer
  • 15,457
  • 7
  • 74
  • 102
  • In other words, 'provided but optional' does not have sense? Does `provided` means that users MUST provide the implementation? – igr Dec 22 '13 at 22:18
  • It depends on your code, but mostly the answer is yes. You are in great risk of a class not found exception if the dependency is not provided, although you may be able to code around that depending on how your app is configured. Generally, it's a bit hard. Optional dependencies aren't meant for this. – Software Engineer Dec 22 '13 at 22:20