24

I am working on a gem (Gem A) which uses another gem (Gem B) that I have also written. Until this point Gem B has been added in the gemspec for Gem A:

gem.add_dependency "gem_a", "~> 0.0.4"

But I now find the need to debug using my local version.

To declare a local dependency in a Gemfile I could do:

gem 'gem_a', path: "/local/path/to/gem_a"

But how do I declare a local dependency in a .gemspec?

Undistraction
  • 42,754
  • 56
  • 195
  • 331
  • Not sure if this can be done, but it would be useful if gems are being co-developed. Trouble is the two declarations of dependency are for two different installers to process. What would `gem build` do with a local dependency? The resulting package couldn't be reliably distributed. – Neil Slater Sep 07 '13 at 19:47

2 Answers2

20

Just so folks can find the answer (slightly) faster...

If you're creating a gem, and need to add a local dependency (while developing), in your gem's Gemfile, do something like:

source 'https://rubygems.org'

# Specify your gem's dependencies in mygem.gemspec
gemspec

gem "local_gem", path: "/path/to/local_gem"

When you bundle you should see it's now using the local path

Using local_gem 0.1.0 from source at `/path/to/local_gem`
tehprofessor
  • 2,957
  • 1
  • 21
  • 22
  • Late to the party - but, if I develop a gem locally, then `gem install my_new_gem.gem` to install it locally, I still cannot add it as a dependency in a `gemspec` file right? It appears that installing a gem locally doesn't really do anything? – Brian May 28 '18 at 02:06
4

Hm...what about adding it in gem's Gemfile in :development group?

UPD: I found similar question, maybe this helps

How to add dependency of a local gem to a rails plugin/engine, in .gemspec file

Community
  • 1
  • 1
Bob
  • 2,081
  • 18
  • 25
  • Thanks, but unfortunately that doesn't work. I've tried it before and after the `gemspec` call. For some reason it can't see the gem - I get a '… in `require': cannot load such file -- gem_b (LoadError)' – Undistraction Sep 07 '13 at 20:10