How to override gem dependency? - ruby-on-rails

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?

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.

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.

Related

Ruby gem conflicts

I'm trying to update a specific Slack-Client gem from version 1 to version 2.
The problem that the version 2 uses another gem called Faraday with version 2 and I have in Gemfile another gem called Kit that uses Faraday version 1.
Bundler could not find compatible versions for gem "faraday":
In snapshot (Gemfile.lock):
faraday (= 1.10.2)
In Gemfile:
oktakit was resolved to 0.3.3, which depends on
faraday (>= 0.17.3, < 2)
slack-ruby-client (= 2.0.0) was resolved to 2.0.0, which depends on
faraday (>= 2.0)
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
I would like to know if there is a way to update Slack-Client to version 2 without create a new conflict
I've tried different approaches, but all of them create the same error
You cannot require the same gem multiple times in different versions in your application at the same time. In your case, this means that you cannot update slack-ruby-client to a version that requires faraday >= 2.0 while keeping the oktakit gem at a version that requires faraday < 2.
Because there is no never version of oktakit available, you are stuck and have to wait for oktakit to be updated.
What you could try, is forking those gems and try if one of them would work with the faraday version required by the other. Or you investigate if you can replace oktakit with any other Okta related gem that supports your use case.

Bundler fails because it can't find compatible version of faraday gem

I'm trying to install a the instagram-ruby-gem but bundler keeps failing with this error:
Bundler could not find compatible versions for gem "faraday":
In Gemfile:
instagram (>= 0) ruby depends on
faraday (< 0.9, >= 0.7.4) ruby
instagram (>= 0) ruby depends on
faraday (0.9.0)
Here's my Gemfile:
gem 'instagram', git: 'https://github.com/larrylv/instagram-ruby-gem.git'
I am using this specific fork because it fixes the faraday version to be compatible with Rails 4. See the commit here, but here's the change:
- s.add_runtime_dependency('faraday', ['>= 0.7', '< 0.9'])
+ s.add_runtime_dependency('faraday', '>= 0.7.4', '<= 0.9.0')
I already tried bundle update. That did not work. The only faraday version installed is faraday 0.9.0.
I downloaded the forked gem, built it and then installed it. It looks like it went through without any issues on my end. So it is something to do with the environment or a gem conflict issue. I'd check to make sure you don't have any other versions of the gem installed. Do you use RVM by any chance and use gemsets with RVM? As a last resort you could delete the Gemfile.lock, but that is not really recommended. You could look at the Gemfile.lock file as well and look at the faraday references. Perhaps other gems need a certain version and the forked gem you use requires another version? I have run in to that before. It is not fun to try and resolve.
Mike Riley

Bundler could not find compatible versions for gem "bundler"

Trying to install a new gem into a rails app and regardless of whether I add or remove a gem from the Gemfile, when I run bundle install, I get the following error:
Bundler could not find compatible versions for gem "bundler":
In Gemfile:
rails (= 3.0.0) ruby depends on
bundler (~> 1.0.0) ruby
Current Bundler version:
bundler (1.3.5)
This Gemfile requires a different version of Bundler.
Perhaps you need to update Bundler by running `gem install bundler`?
I am confused, because ~> 1.0.0 means that I have to have a version of bundler equal to or greater than 1.0.0 but less than 2.x.x. I'm fulfilling this requirement, so why is it failing?
Just to add, if I leave the Gemfile as is, bundle install works just fine.
UPDATE
Clearly, I misunderstood the ~> symbol. You can look at the checked answer below for an explanation, or an even more in depth one at Meaning of tilde-greater-than (~>) in version requirement?
Actually ~> 1.0.0 is equal to >= 1.0.0 && < 1.1, so 1.3.5 doesn't match. You need another bundler version.

Is there a way around this gem dependency issue?

I want to use both the twitter gem and the pingdom-client gem in a small api health/status site I need to build.
When I try to bundle install the pingdom-client gem, I get the following error.
Bundler could not find compatible versions for gem "faraday":
In Gemfile:
pingdom-client (>= 0) ruby depends on
faraday (~> 0.5.6) ruby
twitter (>= 0) ruby depends on
faraday (0.8.4)
What are my options for resolving this issue? Or do I need to abandon the use of one of these gems?
There isn't a newer version of pingdom-client available with a better dependency, so you can try creating one on your own.
Uninstall all versions of faraday with gem uninstall faraday
Fork pingdom-client.
Change it's dependency on faraday to (~> 0.8.4) it it's pingdom-client.gemspec
Change your Gemfile line to
gem 'pingdom-client', git: 'url/to/your/git/fork.git'
Run bundle
Check your application to see if all is well with pingdom-client running the newer version of faraday

hashie gem conflict while require twitter gem

Hey when i try to 'require' the gem -> twitter (1.6.2) in my rails app I get an error
can't activate hashie (~> 1.1.0, runtime) for ["twitter-1.6.2"], already activated hashie-1.2.0 for ["instagram-0.8.4"]. I did 'gem list' and saw this hashie (1.2.0, 1.1.0). I removed the 1.1.0 version of hashie and that gave another error RubyGem version error: hashie(1.2.0 not ~> 1.1.0). How do I solve this issue?
You should probably look into upgrading the version of the twitter you're using. 1.6.2 is at least a year old. The gem is now on version 3.x and no longer has the hashie dependency.
If this isn't an option for you, you're really just left with forking the twitter gem source, modifying the 1.6.2 tag to suit your needs by either removing the hashie dependency or raising it's dependency version in twitter.gemspec, and then referring to your git fork in your Gemfile
gem "twitter", git: "git://github.com/...", "1.6.2"
Whether removing or raising the version restriction on the hashie gem dependency, you should re-run the tests for the twitter gem before deploying your site with this change.

Resources