10

在我自己的 gem 中,我有一个Gemfile基本上是这样的:

source 'https://my.gemserver.com'
source 'https://rubygems.org'

gemspec

.gemspec的所有依赖项都列为add_dependencyadd_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 规范中找不到任何关于源选项的信息。

4

3 回答 3

6

不,您需要将警告静音或将源代码块添加到Gemfile您想要来自您的私人服务器的特定宝石。不需要复制来自的那些rubygems.org(或者你可以反过来做,如果你依赖的私有宝石多于公共宝石,并且你的私人宝石本身不依赖于公共宝石)。

问题是该gemspec格式不支持为每个 gem 指定来源,因此如果不将它们复制到 中Gemfile,就无法指定哪些 gem 来自每个来源。

于 2015-03-11T05:13:25.220 回答
6

有点难过,但必须将其移至 Gemfile :-(

宝石文件:

source 'https://my.gemserver.com' do
  your_gem1
  your_gem2
  #...
end

source 'https://rubygems.org'

gemspec

但是,如果您的一些宝石应该包含在:development:test组中,则可以使用以下

宝石文件:

your_gem1, :source => 'https://my.gemserver.com'
#...
group :development do
  your_gem2, :source => 'https://my.gemserver.com'
  #...
end

source 'https://rubygems.org'

gemspec
于 2016-02-10T11:32:32.453 回答
2

如先前的答案所述,要详细说明有关bundler问题的讨论,您必须将 gem 包含在您中Gemfile。但是,您只需要在.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
于 2017-04-25T16:23:18.810 回答