Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I force a gem's dependencies in gemfile?

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?

like image 592
Lai Yu-Hsuan Avatar asked Sep 15 '11 16:09

Lai Yu-Hsuan


People also ask

How do you install gems you added to your Gemfile?

run the command bundle install in your shell, once you have your Gemfile created. This command will look your Gemfile and install the relevant Gems on the indicated versions. The Gemfiles are installed because in your Gemfile you are pointing out the source where the gems can be downloaded from.

How do I resolve gem dependencies?

Common Attempts To Resolve Ruby Gem Dependencies Bundler can help to resolve dependencies when working with Ruby gems by allowing you to specify a set of gems in a Gemfile, then issue a single command to install them. Bundler then automatically resolves the dependencies for you.


1 Answers

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'
like image 199
Pan Thomakos Avatar answered Sep 20 '22 13:09

Pan Thomakos