我可以在gemfile中强制创建一个gem的依赖关系吗? [英] Can I force a gem's dependencies in gemfile?

查看:115
本文介绍了我可以在gemfile中强制创建一个gem的依赖关系吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有两个宝石, A B A1.0.0 取决于 B1.0.0



在我的Gemfile中:

  gem'A','〜> 1.0.0'

然后运行 bundle 。它会生成一个Gemfile.lock,如下所示:

  A(1.0.0)
B(1.0.0)

但是如果我想强制 A 来使用 B1.0.1 ,最佳做法是什么?此外,如果 B1.0.1 不是释放而是一个github标签?

您需要在您的Gemfile中明确指定B gem以使用git存储库或其他版本。只要A 1.0.0与B 1.0.1兼容,你就可以。如果它仅与B 1.0.0兼容,那么您将不得不创建自己的A gem分支,并将gemspec升级为与B 1.0.1兼容,然后将该存储库用作A的宝石,而不是rubygems版本。



如果A 1.0.0与B 1.0.1兼容,以下是一个示例Gemfile,它应该为您提供所需内容。

  gem'B',::git => 'git://github.com/B/B.git',:tag => '1.0.1'
gem'A','〜> 1.0.0'


If there are two gems, A and B. A1.0.0 depends on B1.0.0.

In my Gemfile:

gem 'A', '~> 1.0.0'

Then run bundle. It will generate a Gemfile.lock like:

A (1.0.0)
  B (1.0.0)

But if I want to force A to use B1.0.1, what's the best practice? Moreover, if the B1.0.1 is not release but a github tag?

解决方案

You'll need to explicitly specify the B gem in your Gemfile to use a git repository or another version. As long as A 1.0.0 is compatible with B 1.0.1 you'll be fine. If it is only compatible with B 1.0.0 then you'll have to create your own fork of the A gem and upgrade the gemspec to be compatible with B 1.0.1 and then use that repository as your gem for A instead of the rubygems version.

Here is a sample Gemfile that should give you what you want, provided A 1.0.0 is compatible with B 1.0.1.

gem 'B', :git => 'git://github.com/B/B.git', :tag => '1.0.1'
gem 'A', '~> 1.0.0'

这篇关于我可以在gemfile中强制创建一个gem的依赖关系吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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