ruby 如何为gemspec中声明的依赖项指定源代码?

nkkqxpd9  于 2022-11-22  发布在  Ruby
关注(0)|答案(1)|浏览(102)

当在gemfile中指定多个全局源时,Bundler(自1.7版起)会发出警告。您可以使用源块来指定哪些gem应来自给定源,但单个gem的源选项在gemspec中不起作用。
如何在gemspec中指定依赖项的源代码?

Gem::Specification.new do |s|
  # Gemspec contents omitted for brevity 

  # Lets say this one comes from RubyGems.org 
  s.add_runtime_dependency 'aruntimedep', '~> 1.0'

  # And this one needs to be sourced from a private gem server
  s.add_development_dependency 'adevdep',  '~> 3.0'

  # Note, Bundler throws an error in this case
  # s.add_development_dependency 'adevdep',  '~> 3.0', :source => "mygemserver.org"

end
9jyewag0

9jyewag01#

不能。您不能在.gemspec文件中指定源。
要尝试使其工作,您可以执行以下操作:

#Gemfile

source 'https://rubygems.org'

source 'https://mygemserver.org' do
   gem 'adevdep'
end

#gemspec

Gem::Specification.new do |s|
  # Lets say this one comes from RubyGems.org 
  s.add_runtime_dependency 'aruntimedep', '~> 1.0'

  s.add_development_dependency 'adevdep', '~> 0.2'
end

看问题汇报:https://github.com/bundler/bundler/issues/3576

相关问题