myconode
myconode

Reputation: 2617

How to specify source for a dependency declared in gemspec?

Bundler since v1.7 issues a warning when more than one global source is specified in the gemfile. You can use source blocks to specify which gems should come from a given source, but the source option for individual gems does not work in the gemspec.

How can one specify the source for a dependency in the gemspec? E.g.

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 

Upvotes: 2

Views: 1518

Answers (1)

morhook
morhook

Reputation: 1209

No. You can't specify the source in .gemspec files.

To try to make it work you can do the following:

#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

Look at issue reported: https://github.com/bundler/bundler/issues/3576

Upvotes: 3

Related Questions