Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Import-Package resolution:=optional and no dependency at all

Tags:

osgi

I have read here to use the optional resolution within the "Import-Package" directive carefully, but don't really understand why. Also what is the difference between optional and not specifying a dependency at all?

like image 723
V G Avatar asked Dec 25 '22 16:12

V G


1 Answers

If you fail to specify an Import-Package at all, then your bundle cannot access the package even if it available and exported by some other bundle.

If you import the package optionally, then your bundle can use it if available, but that package not being available does not prevent resolution of your bundle.

You should avoid optional dependencies at the package level. Either you depend on a package or you don't. Normally a need for optional dependencies indicates that your bundle has poor coherency, i.e. it's doing too many unrelated things within one module.

like image 197
Neil Bartlett Avatar answered May 14 '23 17:05

Neil Bartlett