简体   繁体   English

更新在另一个 gem 依赖项中指定的 gem 版本

[英]update gem version that is specified in another gem dependency

In my Gemfile, I'm including a gem that has a .gemspec that uses the pessimistic operator ~> to specify a version of the gem.在我的 Gemfile 中,我包含了一个具有 .gemspec 的 gem,它使用悲观运算符~>来指定 gem 的版本。 However, I need to use a newer version of the gem.但是,我需要使用更新版本的 gem。 In my case I'm using spree 3-0-stable that has activemerchant set to '~> 1.47.0' https://github.com/spree/spree/blob/3-0-stable/core/spree_core.gemspec#L22 but I need use active merchant '~> 1.59.0'在我的情况下,我使用的是 spree 3-0-stable,它的 activemerchant 设置为“~> 1.47.0” https://github.com/spree/spree/blob/3-0-stable/core/spree_core.gemspec #L22但我需要使用活跃商家 '~> 1.59.0'

I tried to specify version 1.59.0 in my Gemfile but bundle complains with:我试图在我的 Gemfile 中指定版本 1.59.0 但 bundle 抱怨:

You have requested: activemerchant ~> 1.59.0您已请求:activemerchant ~> 1.59.0

The bundle currently has activemerchant locked at 1.47.0.该捆绑包当前已将 activemerchant 锁定在 1.47.0。 Try running bundle update activemerchant尝试运行bundle update activemerchant

If you are updating multiple gems in your Gemfile at once, try passing them all to bundle update如果您一次更新 Gemfile 中的多个 gem,请尝试将它们全部传递给bundle update

But the command bundle update activemerchant will only update to 1.47.x.但是命令bundle update activemerchant activemerchant 只会更新到 1.47.x。

What's the rails-y way of accomplishing this?实现此目的的 rails-y 方式是什么? Aside from forking spree myself and updating the .gemspec?除了自己分叉狂欢和更新.gemspec? Obviously updates to the activemerchant gem might break the spree gem.显然,对 activemerchant gem 的更新可能会破坏狂欢 gem。 But I can test with my app.但我可以用我的应用程序进行测试。

The maintainers of Bundler have recommended forking the relevant gem, then making a PR back onto the gem. Bundler的维护者建议分叉相关的 gem,然后在 gem 上做一个 PR。 Then link directly to the branch in that PR in your Gemfile .然后直接链接到Gemfile中该 PR 中的Gemfile This encourages the community to rally around a solution.这鼓励社区围绕解决方案团结起来。

I've documented the process in detail here:https://github.com/rubygems/rfcs/pull/13#issuecomment-770416467我在这里详细记录了这个过程:https ://github.com/rubygems/rfcs/pull/13#issuecomment-770416467

You can't do it, the rubygems system doesn't allow that.你不能这样做,rubygems 系统不允许这样做。 You have to file an issue for the upstream gem dependency, and ask them to loosen their requirements.您必须为上游 gem 依赖项提交问题,并要求他们放宽要求。

It may be that the version of activemerchant you want actually won't work with the version of spree you want, it will break it.可能是您想要的 activemerchant 版本实际上无法与您想要的 spree 版本一起使用,它会破坏它。 If so, spree code would have to be fixed to work with the new version of activemerchant.如果是这样,则必须修复狂欢代码才能与新版本的 activemerchant 一起使用。 Or, it could work fine with the version you want, the restriction in spree is accidentally unneccesarily strict, in which case the spree gemspec would just have to be changed to allow it.或者,它可以与您想要的版本一起正常工作,spree 中的限制意外地不必要地严格,在这种情况下,只需要更改 spree gemspec 以允许它。

But there's no way for you to override it without changing the spree gemspec.但是您无法在不更改狂欢 gemspec 的情况下覆盖它。

You could make your own fork of spree in which you change the gemspec -- but without knowing whether or not spree will really work with the version of activemerchant you want, that could be dangerous.您可以制作自己的狂欢分支,在其中更改 gemspec - 但不知道狂欢是否真的适用于您想要的 activemerchant 版本,这可能很危险。 And now you're on your own fork, so you won't be able to upgrade to new versions of spree without merging in their changes to your fork, etc.现在你在你自己的 fork 上,所以你将无法升级到新版本的 spree 而不将他们的更改合并到你的 fork 等。

Another thing is, it's a bit odd to be running off a spree 3-0-stable branch, instead of an actual released version of the gem.另一件事是,运行spree 3-0-stable分支而不是 gem 的实际发布版本有点奇怪。 But I'm not familiar with spree's release management practices, perhaps this is what they encourage?但是我不熟悉 spree 的发布管理实践,也许这就是他们所鼓励的? At any rate, changing this probably won't fix your problem.无论如何,更改此设置可能无法解决您的问题。

If your app is relatively new or simple, you could consider switching from spree to solidus , a fork of spree.如果您的应用程序相对较新或比较简单,您可以考虑从 spree 切换到solidus ,这是 spree 的一个分支。 Solidus forked off at spree 2.x though, so migration from spree 3.x might not be straightforward, especially if your app is established and somewhat complex. Solidus 在 spree 2.x 上分叉,所以从 spree 3.x 迁移可能并不简单,特别是如果您的应用程序已经建立并且有些复杂。 Although the solidus_core gem is also locked to activemerchant ~> 1.48.0 , so it also won't allow anything but activemerchant 1.48.x.虽然solidus_core gem被锁定~> 1.48.0 ,所以它也不允许除了 activemerchant 1.48.x 之外的任何东西。 The solidus team is pretty responsive on their Slack channel, if you wanted to ask them what's up with that, if they know if later versions of activemerchant will work, if the dependency can be loosened. solidus 团队在他们的 Slack 频道上非常敏感,如果你想问他们这是怎么回事,他们是否知道以后版本的 activemerchant 是否可以工作,是否可以放松依赖关系。 I have found the solidus maintainers to be very responsive, and likely to be interested in allowing later versions of activemerchant if it's feasible to do.我发现solidus 的维护者非常敏感,并且如果可行的话,可能有兴趣允许更新版本的activemerchant。 I'm not familiar with the current Spree team and how they communicate with users (if they have a slack, or listserv, or are responsive on github issues, or what), but you could of course have the same conversation with them.我不熟悉当前的 Spree 团队以及他们如何与用户沟通(如果他们有空闲时间或列表服务,或者对 github 问题有响应,或者什么),但您当然可以与他们进行相同的对话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM