Downgrade dependency

Hi, I have a custom library A that uses google-api-client v 1.23.0.
I also use library B with google-api-client v 2.0.0
Currently at runtime the library A failed with error:

You are currently running with version 2.0.0 of google-api-client. You need at least version 1.15 of google-api-client to run version 1.23.0 of the Google Cloud Key Management Service (KMS) API library.

I can solve this problem if I add exclude in library B,

Can this solution result in a runtime exception in library B now?

Actually, excluding it in “B” is not really the appropriate approach to downgrading a dependency.
Excludes are most often just a dirty work-around for something that should be solved differently properly and better semanically.
This is detailed at Downgrading versions and excluding dependencies if you scroll down all the way to the last paragraph starting with

Historically, excludes were also used as a band aid to fix other issues not supported by some dependency management systems.

But either way, the answer to your question is yes, most probably.
If B uses that library and is not compatible with 1.x, it will then fail if you use its functionality that uses that library.

Most often libraries are backwards compatible, so that if something needs an older version it can also work with a newer version.
If this is not the case like here, you always have potential problems.
Best solution probably would be if A is upgraded to be compatible with version 2.x of the library.
If you either know for sure you do not need the functionality in B using that library or it actually also works with 1.x, then a proper downgrade is the way to go of course.

If neither using a newer A is an option, nor not using the B functionality that uses that library, you most probably have a serious problem. You would then probably need some sophisticated trickery, like somehow including both versions and using custom class loaders for A and B, so that they can use the different version of that library or similar. Or maybe some relocating of one of the library versions and their usage in one of A or B, but that is of course alwas prone to problems too.

1 Like

Thanks for the details answer is very educated :grinning: