Using different code depending on the version of another dependency

感情迁移 提交于 2019-12-08 06:31:52

问题


Following situation:

  • Library X (maintained by me) depends on library Y version ^2.0.
  • For library Y, a newer major version 3 exists that is generally better.
  • Upgrading code built on top of Y 2 to Y 3 is straightforward, but requires a few adjustments to the existing code nonetheless.
  • Y is a dependency of X, so upgrading it would force users of X to upgrade, too, and thus also requires updating code that uses Y outside of X.

I'd like to make X installable with both Y 2 and Y 3. My approach would be to provide different versions of the code using Y and switch between the versions depending on the installed version, similar to C conditional compilation.

Questions:

  • Is there a better approach to this?
  • How would I implement conditional code like that?
  • Any other comments or suggestions?

来源:https://stackoverflow.com/questions/48158317/using-different-code-depending-on-the-version-of-another-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!