mount986
mount986

Reputation: 75

Bundler - Resolving Dependencies from different sources

My company has a private Gem-in-a-box server where multiple teams can share internally created gems. Recently, a gem has been added to this server which I want to use. It turns out, this gem has a dependency on net-ssh and net-scp, which are available from ruby-gems.org, and are not stored on the Gem-in-a-box server. When I add the new gem to my Bundler Gemfile and run an install, I get the following error:

C:\jruby-1.7.18\bin\jruby.exe --1.9 C:\jruby-1.7.18\bin/bundle install

Fetching source index from http://my.server.org/geminabox/
Fetching gem metadata from http://rubygems.org/.
Fetching source index from http://my.server.org/geminabox/
Fetching gem metadata from http://rubygems.org/.
Fetching additional metadata from http://rubygems.org/........
Resolving dependencies...
Could not find gem '["net-ssh", "net-scp"] (>= 0) java', which is required by
gem 'gem_dependent_on_ssh (>= 0) java', in any of the sources.

Process finished with exit code 6

Here is a snippet from my Gemfile:

source 'http://rubygems.org' do
  gem 'net-scp'
  gem 'net-sftp'
end

source 'http://my.server.org/geminabox/' do
  gem 'gem_dependent_on_ssh'
end

It looks like it is only looking for gem dependencies on the same server as the gem being loaded in... Is there something I can add to my Gemfile to get around this? Or, can I go to the team that created the gem and have them add something to tell it where to look for dependencies? Or, is the only solution to add the net-ssh and net-scp gems to the Gem-in-a-box server so it can find them as a local dependency?

Thanks in advance!

Upvotes: 2

Views: 1474

Answers (2)

alexcavalli
alexcavalli

Reputation: 536

It looks like the docs say no (very bottom):

SOURCE PRIORITY

When attempting to locate a gem to satisfy a gem requirement, bundler uses the following priority order:

  1. The source explicitly attached to the gem (using :source, :path, or :git)
  2. For implicit gems (dependencies of explicit gems), any source, git, or path repository declared on the parent. This results in bundler prioritizing the ActiveSupport gem from the Rails git repository over ones from rubygems.org
  3. The sources specified via global source lines, searching each source in your Gemfile from last added to first added.

The relevant one being #2 here. It's a little vague but I think this other part of the docs helps clarify:

Bundler will search for child dependencies of this gem by first looking in the source selected for the parent, but if they are not found there, it will fall back on global sources using the ordering described in SOURCE PRIORITY.

So it sounds like you need to provide rubygems.org as the fallback global source if you want that to be the case, i.e. using the source 'http://rubygems.org' line on its own as you have done in your answer. Otherwise when looking for child gems (dependencies) it will look only on the source provided for the parent.

That said, I also have a company Gem-in-a-box server and tried to reproduce your issue but could not, so I'm not positive I'm interpreting those docs correctly.

Upvotes: 1

mount986
mount986

Reputation: 75

After consulting with a few other sources, it appears that if you remove the blocks and simply declare the sources, it manages to install all gems:

source 'http://rubygems.org'
source 'http://my.server.org/geminabox/'

gem 'net-scp'
gem 'net-sftp'
gem 'gem_dependent_on_ssh'

While this does fix this specific issue, I can still imagine a scenario where you would want to specify the source for a specific gem, and yet use it to resolve a dependency in another source. So while our issue is resolved, the question still stands.

Upvotes: 0

Related Questions