Can I force a gem's dependencies in gemfile?

痞子三分冷 提交于 2019-11-30 01:14:02

问题


If there are two gems, A and B. A1.0.0 depends on B1.0.0.

In my Gemfile:

gem 'A', '~> 1.0.0'

Then run bundle. It will generate a Gemfile.lock like:

A (1.0.0)
  B (1.0.0)

But if I want to force A to use B1.0.1, what's the best practice? Moreover, if the B1.0.1 is not release but a github tag?


回答1:


You'll need to explicitly specify the B gem in your Gemfile to use a git repository or another version. As long as A 1.0.0 is compatible with B 1.0.1 you'll be fine. If it is only compatible with B 1.0.0 then you'll have to create your own fork of the A gem and upgrade the gemspec to be compatible with B 1.0.1 and then use that repository as your gem for A instead of the rubygems version.

Here is a sample Gemfile that should give you what you want, provided A 1.0.0 is compatible with B 1.0.1.

gem 'B', :git => 'git://github.com/B/B.git', :tag => '1.0.1'
gem 'A', '~> 1.0.0'


来源:https://stackoverflow.com/questions/7434263/can-i-force-a-gems-dependencies-in-gemfile

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