0

Say, I have Gemfile like following.

source "GEM_REPOSITORY"

gem 'gem_A'
# gem_A has no additional dependency

gem 'gem_B'
# gem_B depends on gem_B_1 and gem_B_2

When I run bundle install, I want Bundler to do the following.

  1. If a gem already exists in "local system-wide gems", it copies the gem from local.

  2. If a gem doesn't exist in local, it looks for GEM_REPOSITORY.

I looked for some related articles, and found some of likely-answers like

But none of the above looks like the answer for me. Using source repository priority does't work. Because in the example above, if dependent gem (say, gem_B_1) exits in local but the target gem (gem_B) doesn't exist in local, it'll download both of above from the remote repository.

Are there any work around for doing this? If not, don't you guys think it's necessary considering the cost of the implementation and the effect?

Community
  • 1
  • 1
Ryo
  • 2,003
  • 4
  • 27
  • 42

1 Answers1

1

This is the current behavior. When running gem install, directly or via bundle install, gem will first build a dependency graph with all the needed gems. If the gem is found locally it will use it, otherwise it will try to download it from the specified source.

If you want, try it yourself.

bundle gem gem_a
bundle gem gem_b
cd gem_a
vim gem_a.gemspec

add

spec.add_dependency 'multi_json', '~> 1.10.1'

or any dependency you want to the gem and run bundle install.

cd ../gem_b
vim Gemfile

and add

gem 'gem_a', path: '../gem_a'

then run

bundle install --verbose

you will see that the multi_json or whatever dependency of gem_a uses the local version and does not download anything.

This is of course also true for gems from remote sources.

Daniel Perez
  • 6,335
  • 4
  • 24
  • 28