Java – use spring without exposing dependencies to client applications
I'm writing Java APIs for several clients and internally want to use spring and several of its functions, but I don't want to expose my dependencies to clients
Is that possible?
Therefore, if my clients use different versions of spring, they will be isolated from my internal spring dependencies
If so, will my spring dependencies be bundled inside my jar? Does my client application need a custom classloader?
I heard you can use it through OSGi bundle, but I want to know if it meets my requirements
The client of my API will not enable OSGi, or we do not use the current environment of OSGi bundle
Solution
This is not feasible or desirable Why do you "hide" dependencies? Do you also want to hide dependencies on any log packages you may be using (for example)?
If there are dependencies in your implementation, it's best to release them, because it will make your API users more sad, because they will know what conflicts may exist before trying to use your code
Don't forget that your users are actually developers, and I believe they would rather know any mines or requirements in advance
Edit – about OSGi:
OSGi will certainly handle your conflicting dependencies, but it will also depend on deployment in OSGi environment. What you haven't mentioned is your client In addition, it is still not recommended to "hide" these dependencies in the bundle The nature of OSGi allows confusing dependencies to cooexist in the same application