如何同时使用不同版本的gem [英] How to use different versions of a gem at the same time

查看:112
本文介绍了如何同时使用不同版本的gem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在一个应用程序中使用两个版本的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会冻结我的终端.

是否可以同时使用两个插件?

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆