2 gems need different versions of the same depende

2019-02-12 09:05发布

Using Rails 3, I'm trying to figure out what I think should be pretty straightforward...

I have 2 gems that require 2 different versions of the same gem dependency. Both versions of the dependent gem are installed on my system but I still get an error from Rails: "Bundler could not find compatible versions for gem XXX".

What is the best practice to handle a scenario like this?

6条回答
做个烂人
2楼-- · 2019-02-12 09:08

Take a look at this solution, maybe it will help you: gems

查看更多
欢心
3楼-- · 2019-02-12 09:09

If you don't need all the features of the Twitter gem version 1.4.1, you could use version 1.2.0, which needs faraday ~> 0.5.4. and that should work. If that doesn't, you could try poking the owner of groupon2 to update his gem--it's on github https://github.com/gangster/groupon2 .

查看更多
别忘想泡老子
4楼-- · 2019-02-12 09:10

If you're in a situation where the gems are being used in different projects or at least not at the exact same time you can use RVM's gemset feature as a workaround. I recently had a gem incompatibility similar to yours and that's what I used.

If you have RVM installed, do this:

rvm gemset create gemset_name_here
rvm gemset use gemset_name_here

So what you're doing is creating a gem environment that's totally fresh and from scratch while still being able to revert back to the gems you were working with before at any time. The first line creates a new gemset and the second line tells RVM to start using it.

At this point you'll need to run bundle install or rake or whatever you're using to get the gems you need but this should take care of the problem.

So when you're using gem 1 with dependency 1 you use the gemset that has the required version. Then when you're using gem 2 with dependency 2 you switch to the gemset that has that.

Now, if both gems are part of one larger project this will not be feasible and you'll most likely need to edit the source to of the gem to run the new version of the dependency like @BaroqueBobcat said. In a lot of cases this is actually pretty easy. Ruby developers tend to be very awesome about making their code easy to pick up on.

查看更多
冷血范
5楼-- · 2019-02-12 09:12

bundle update resolve conflicts

查看更多
The star\"
6楼-- · 2019-02-12 09:17

I was having the same issue, but in a different context: Writing an app which uses two different versions of the hashie dependency (1.2.0 and 3.1.0)

I went into the Gemfile.lock and specified the older version in parentheses hashie (1.2.0), ran bundle install, and it worked.

查看更多
SAY GOODBYE
7楼-- · 2019-02-12 09:24

I'd go for what @BaroqueBobcat suggests. I just want to add that - if you need the latest Twitter gem and can't wait for the maintainer of Groupon2 to update his gem - you can fork the Groupon2 on GitHub, update its gemspec, see if it still works by running its tests (and try to fix it if it doesn't) and include your own version using its Git URL in your Gemfile like so: gem "groupon2", :git => "https://github.com/yourgithubuser/groupon2.git".

If you want to be nice you can offer your changes to the maintainer of Groupon2 with a pull request for bonus points :)

查看更多
登录 后发表回答