I have 2 Maven artifacts with 2 versions, lets say A1, A2, B1, B2. B1 depends on A1, B2 depends on A2. A1 and A2 are very similar, lets say A1 is using Java 7 and A2 is using Java 8 and lambdas. All artifacts are used by our clients and sometimes they install the wrong artifact for their environment.
I want to build a base A artifact, A1 and A2 will inherit A and add custom functionality and another artifact, A_Client, and I want to choose at runtime
based on some properties(JDK and some others) which Ax module should be used. This way, our clients will have to install A_Client and they will not have to worry about the right version.
B1 and B2 are the same, the only thing that's different is their Ax dependency. If I can merge A1 and A2 somehow, I will have only a B artifact available for clients that will depend only on A_Client. This way I will eliminate the B versions hell too.
So, the question:
Is it possible to decide at runtime
a dependency? My guess is that it may be possible using OSGi or custom Class loaders, but I have very limited knowledge in both areas so any help is appreciated.