如何在Bundler中解决Gem兼容问题?

时间:2015-07-27 19:13:56

标签: ruby-on-rails ruby gem rubygems bundler

在我们的rails应用程序中,我们使用两个需要rest-client的宝石(urbanairship和nylas)。一个人想要~> 1.6.7而另一个想要~> 1.7.1

通常的bundle udpaterm Gemfile.lock; bundle install不起作用。

Bundler解析依赖关系时,我们得到了这个:

Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies............................................................................................................................................
Bundler could not find compatible versions for gem "rest-client":
  In Gemfile:
    urbanairship (~> 3.0.1) ruby depends on
      unirest (>= 1.1.2, ~> 1.1) ruby depends on
        rest-client (~> 1.6.7) ruby

    nylas (>= 0) ruby depends on
      rest-client (~> 1.7) ruby

我们无法使用nylasurbanairship的不同版本。我们正在寻找的唯一解决方案是分配其中一个并编辑.gemspec以接受相同版本的rest-client

有没有更简单的解决方案?

1 个答案:

答案 0 :(得分:0)

Finally, ended up following Chris advice.

  1. Forked nylas https://github.com/hartator/nylas-ruby/

  2. Relaxed Gemfile requirements for rest-client. (was 1.7)

    gem 'rest-client', '~> 1.6'

  3. Relaxed nylas.gemspec requirements for rest-client. (was 1.7)

    s.add_dependency(%q<rest-client>, ["~> 1.6"])

  4. Relaxed nylas.gemspec runtime requirements for rest-client. (was 1.7)

    s.add_runtime_dependency(%q<rest-client>, ["~> 1.6"])

  5. Ran specs, everything was still passing.

  6. Added the altered gem to my application Gemfile

    gem 'nylas', git: 'git@github.com:hartator/nylas-ruby.git'

Everything is working. Still wondering if there is a cleaner solution out there.

Ref: https://github.com/hartator/nylas-ruby/commit/f7ff4076e96d8a31e223ca0f12d35811d6e9d811