问题描述
我可以在一个应用程序中使用两个版本的 gem 吗?
Can I use two versions of a gem in one application?
我正在尝试使用两个 Rails 插件一起工作:
I'm trying to use two Rails plugins to work together:
- Pengwynn 的 LinkedIn 用于 LinkedIn API 调用,依赖于 OAuth (~> 0.3.5)
- OmniAuth 用于用户通过多个知名网站登录,依赖于 OAuth 0.4.0
- Pengwynn's LinkedIn for LinkedIn API calls, has an dependency on OAuth (~> 0.3.5)
- OmniAuth for user login via multiple well-known websites, has an dependency on OAuth 0.4.0
当我在 Rails 中尝试某些东西时,我收到以下错误消息:
When I try something in Rails I get this error message:
$ rails server
c:/Ruby187/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/resolver.rb:129:in `resolve': Bundler could not find compatible versions for gem "oauth": (Bundler::VersionConflict)
In snapshot (Gemfile.lock):
oauth (0.4.4)
In Gemfile:
linkedin depends on
oauth (~> 0.3.5)
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
尝试 bundle update
会冻结我的终端.
Trying bundle update
freezes my terminal.
可以同时使用两个插件吗?
Is it possible to use both plugins at the same time?
推荐答案
使用单个gem的两个版本通常意味着:使用同一个类的两个版本.
Using two versions of a single gem usually means: use two versions of the same class.
不修改这些宝石是不可能的.您可以尝试将创建的类放在某个模块中,解决导入其他类的方法中的冲突,等等.总的来说,这不是一件容易的事,而且通常效果不值得.
It's not possible without making modifications to these gems. You may try to place created classes in some module, resolve conflicts in methods imported into other classes, and so on. In general, it is not easy task, and usually the effect is not worth it.
在这种情况下,你应该应该做的是让 gem 维护者更新依赖关系,或者尝试自己做.
What you should do in such cases is to ask the gem maintainers to update the dependencies, or try to do it yourself.
也许您可以将其中一个 gem 降级(使用旧版本)到依赖项相同的版本.
Maybe you can downgrade (use older version of) one of these gems, to the version in which the dependencies were the same.
这篇关于如何同时使用不同版本的 gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!