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

osgi

Solution

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.

Problem

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?

Original source