如何在rails Gemfile中指定间接gem依赖版本

问题描述

在我的 Gemfile 中,我有:

 gem 'msgpack_rails'
 gem 'google-authenticator-rails'
 .. etc

Gemfile.lock 里面我看到:

google-authenticator-rails (2.0.0)
      actionpack
      activerecord
      google-qr
      rails
      rotp (= 3.3.0)

如何在 google-authenticator-rails gem 中指定 actionpackactiverecord 版本?。

我需要像这样直接在Gemfile.lock里面写:

google-authenticator-rails (2.0.0)
  actionpack (>2)
  activerecord (>6)
  google-qr
  rails
  rotp (= 3.3.0)

解决方法

要直接回答您的原始问题,更新 Gemfile.lock 部分的正确方法是在此处收紧版本限制:https://github.com/jaredonline/google-authenticator/blob/a5d3d344cf8f10abd4c0bf85606c632dce48ca80/google-authenticator.gemspec#L27-L32

但是,我没有看到任何证据表明这是必要的。我认为您对 dependenciesconstraints 感到困惑。

您的项目已经在使用 activerecord 版本 6.0.3.2。收紧 google-authenticator-rails 的约束不会改变这一事实。

您可以通过运行以下命令查看您的项目使用的所有依赖项的版本:bundle list

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...