Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override gem dependency?

I have 2 gems that depend on conflicting versions of hashie (one requires ~> 1.2.0 and the other requires 3.3.1):

Bundler could not find compatible versions for gem "hashie":
  In Gemfile:
    restforce (>= 0) ruby depends on
      hashie (~> 1.2.0) ruby

    omniauth (>= 0) ruby depends on
      hashie (3.3.1)

I'd like to keep both gems and use the higher version of hashie. Is there a way for me override one of the gem dependencies?

like image 205
user3827303 Avatar asked Oct 28 '14 23:10

user3827303


People also ask

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.

How do I check gem dependencies?

You can always check the reverse dependencies of a gem on rubygems.org. There's a link on the right side panel on the website.

What is gem require false?

You use :require => false when you want the gem to be installed but not "required". So in the example you gave: gem 'whenever', :require => false when someone runs bundle install the whenever gem would be installed as with gem install whenever .


2 Answers

The standard advise is to use the higher version compatible.

I do this way, but I think bundler has a defined command for it.

First remove the line of gem 'omniauth' at your Gemfile. Run bundle install, then you must add again the line with gem 'omniauth' to your Gemfile, run bundle install again.

If you look at Gemfile.lock, this install hashie 2.0.5, the higher compatible.

Edit: why does this work?

First I check omniauth dependencies with hashie: hashie < 4, >= 1.2, then the same with restforce: hashie < 2.1, >= 1.2.0. At this point, I know that any version of hashie between 1.2 and 2.0.x must work. Then we must to remove the constraint at Gemfile.lock of continue using hassie 3.3.1, removing 'omniauth' from Gemfile it's done. After that, when install restforce, the bundler find the new version compatible with restforce '2.0.5'. And when you add again omniauth bundler don't update dependencies that are accomplished.

like image 72
Alejandro Babio Avatar answered Sep 24 '22 22:09

Alejandro Babio


I think bundle update is actually what you were after. That sorts out dependencies and installs different versions of gems if required, giving you the most up-to-date gems possible.

Be careful however, as updating gems can introduce compatibility issues.

like image 38
ZimbiX Avatar answered Sep 22 '22 22:09

ZimbiX