如何重写gem依赖关系? [英] How to override gem dependency?

查看:133
本文介绍了如何重写gem依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个宝石取决于相互冲突的hashie版本(一个需要〜> 1.2.0,另一个需要3.3.1):

  Bundler找不到兼容版本的gemhashie:
在Gemfile中:
restforce(> = 0)ruby依赖$ b $ hashie(〜> 1.2.0 )ruby

omniauth(> = 0)ruby取决于
hashie(3.3.1)

我想保留这两个宝石并使用更高版本的hashie。有没有办法让我重写其中的一个gem依赖关系? 解决方案

标准建议是使用更高版本兼容



我这样做,但我认为bundler有一个定义的命令。



<首先在您的Gemfile中删除 gem'omniauth'的行。运行 bundle install ,然后您必须再次将 gem'omniauth'行添加到您的Gemfile中,再次运行bundle install 。



如果你看一下Gemfile.lock,这个安装 hashie 2.0.5 p>

编辑:为什么会有效?

首先我检查 omniauth 依赖与hashie: hashie< 4,> = 1.2 ,那么 restforce hashie< 2.1,> = 1.2.0 。此时,我知道1.2和2.0.x之间的任何hashie版本都必须工作。然后,我们必须使用hassie 3.3.1去除Gemfile.lock中的约束,从Gemfile中删除'omniauth'。之后,安装restforce时,捆绑器会发现与restforce'2.0.5兼容的新版本。而当你再次添加omniauth bundler时,请不要更新已完成的依赖关系。

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.

edited: why it works?

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.

这篇关于如何重写gem依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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