Gemfile 中可以有一个 gem 的多个版本吗?
我想要的是这样的:
gem 'rack', '1.3.3', '1.2.4'
这样当宝石需要不同版本的机架时,他们都会得到安抚。这可能吗?
What I would like would be something like this:
gem 'rack', '1.3.3', '1.2.4'
So that when gems require different versions of rack, they are all appeased. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以设置允许的宝石间隔。
它将加载所选间隔内最实际的宝石。
但我不认为你可以需要不同的 gem 版本。
如果一个 gem 被加载到不同的版本中,每个类和模块都必须有自己的命名空间,以避免覆盖 gem 的方法。
You can set an intervall of allowed gems
It will load the most actual one inside the selected intervall.
But I don't think you can require different gem versions.
If a gem would be loaded in different versions, each class and module must get it own namespace to avoid to overwrite the methods of the gem.
不,您无法同时加载多个 gem 版本。这是因为,正如克努特强调的那样,代码会发生冲突。 gem 如何知道使用
1.2.4
版本的 Rack 而不是1.3.3
版本的 Rack?不可以。另外:对于 Bundler,必须满足所有 gem 依赖项才能完成捆绑过程。如果您有一个 gem,明确需要 Rack 1.2.4(即
= 1.2.4
位于该 gem 的gemspec
中),然后另一个gem 需要 Rack 版本,例如>= 1.3
那么这些 gem 版本会发生冲突,Bundler 会告诉您。No, you are not able to have multiple gem versions loaded at the same time. This is because, as knut highlighted, the code would conflict. How would a gem know to use the
1.2.4
version of Rack as opposed to the1.3.3
version of Rack? It can't.Also: with Bundler, all gem dependencies must be satisfied in order for the bundling process to complete. If you have a gem that explicitly requires Rack 1.2.4 (i.e
= 1.2.4
is in thegemspec
for that gem) and then another gem that requires a version of Rack such as>= 1.3
then these gem versions will conflict and Bundler will tell you so.我遇到这个问题是因为我想将某些有缺陷的上游 gem 版本列入黑名单。虽然您无法执行
gem 'rack'、'1.3.3'、'1.2.4'
,但您可以有多个
!=
约束排除您已知有问题的版本:gem 'rack', '!= 1.3.0.beta2', '!= 1.3.0.beta'
I came upon this question because I wanted to blacklist certain broken upstream gem versions which were buggy. While you can't do
gem 'rack', '1.3.3', '1.2.4'
you can have multiple
!=
constraints to rule out versions that you know to be problematic:gem 'rack', '!= 1.3.0.beta2', '!= 1.3.0.beta'