在我自己的宝石中,我有一个 Gemfile
看起来基本上是这样的:
source 'https://my.gemserver.com'
source 'https://rubygems.org'
gemspec
我的 .gemspec
将所有依赖项列为 add_dependency
和 add_development_dependency
。
截至Bundler 1.8,我收到警告:
Warning: this Gemfile contains multiple primary sources. Using `source` more than
once without a block is a security risk, and may result in installing unexpected gems.
To resolve this warning, use a block to indicate which gems should come from the
secondary source. To upgrade this warning to an error,
run `bundle config disable_multisource true`.
有没有办法解决此警告(没有通过捆绑配置静音)?我在Rubygems规范中找不到任何关于源选项的内容。
不,您需要将警告静音或将源块添加到您的 Gemfile
使用您希望来自私人服务器的特定宝石。没有必要复制来自的那些 rubygems.org
(或者你可以反过来做,如果你依赖更多私人宝石而不是公共宝石,而你的私人宝石本身并不依赖于公共宝石)。
问题是, gemspec
format不支持为每个gem指定源代码,因此不需要将它们复制到 Gemfile
,没有办法指定每个来源的宝石。
有点伤心,但一个人必须把它移到Gemfile :-(
的Gemfile:
source 'https://my.gemserver.com' do
your_gem1
your_gem2
#...
end
source 'https://rubygems.org'
gemspec
但是,如果你的某些宝石应该包括在内 :development
要么 :test
小组,可以使用以下
的Gemfile:
your_gem1, :source => 'https://my.gemserver.com'
#...
group :development do
your_gem2, :source => 'https://my.gemserver.com'
#...
end
source 'https://rubygems.org'
gemspec
详细讨论 该 bundler
问题,正如之前的答案所说,你 必须 包括你的宝石 Gemfile
。但是,您只需要在您的指定中指定gem的版本 .gemspec
。如果你比私有依赖项更频繁地更改版本,这不是一个糟糕的解决方案。
引用没有版本的gem Gemfile
:
# Gemfile
source 'https://rubygems.org'
source 'https://xxx@gem.fury.io/me/' do
gem 'my-private-dependency'
end
gemspec
引用带有版本规范的gem .gemspec
:
# my-gem.gemspec
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Gem::Specification.new do |spec|
spec.add_dependency 'my-private-dependency', '~> 0.1.5'
end