2

I'm trying to add a private gem dependency to a gemspec I'm writing. My Gemfile is:

source 'https://rubygems.org'

gemspec

gem 'my_private_gem', '0.0.1', :git => 'https://username:pwd@bitbucket.org/johnny/my_private_gem.git'

And the relevant line in mygem.gemspec is:

spec.add_dependency 'my_private_gem', '0.0.1'

Now I thought this would work but after running gem build mygem and gem install ./mygem.gem I get: ERROR: Could not find a valid gem 'mygem' (= 0.0.1) in any repository.

What am I doing wrong?

Johnny
  • 7,073
  • 9
  • 46
  • 72
  • Can you try running `bundle` first and then running `gem build mygem && gem install ./mygem.gem`? – Max May 08 '15 at 07:55
  • Sure. Same result :-( – Johnny May 08 '15 at 07:56
  • Apparently it is not possible. See: http://stackoverflow.com/questions/14273178/gem-add-dependency-for-another-local-gem and http://stackoverflow.com/questions/6499410/ruby-gemspec-dependency-is-possible-have-a-git-branch-dependency – Max May 08 '15 at 08:01
  • It appears to be possible according to http://johnpwood.net/2013/11/08/running-a-private-gem-server/ and http://stackoverflow.com/a/22949736/259288 – Johnny May 08 '15 at 08:08
  • 1
    Running your own gem server is different than specifying a git repo as the source of your gem. Feel free to use that approach if it fits your needs. It's a perfectly valid approach, but does carry the additional overhead of maintaining the gem server. – Max May 08 '15 at 08:34
  • Quoting Yehuda Katz: "If you find that you need to develop against a gem that hasn’t yet been released (for instance, Rails often develops against unreleased Rack, Arel, or Mail gems), you can add individual lines in the Gemfile that tell bundler where to find the gems. It will still use the dependencies listed in the .gemspec for dependency resolution, but it now knows exactly where to find the dependency during gem development.". – Johnny May 08 '15 at 09:22

1 Answers1

1

It is possible without creating own gem server.

In case the URL to the gem is correct, most probably you don't have the correct 0.0.1 version specified within the gem's .gemspec file. You need to have: spec.version = '0.0.1' (the dependency you have added is like recursive dependency to itself, I'm not even sure if it can work with it)

Also in most cases it would be easier to have a release branch or tag to which you point the gem instead to a version. As described here: http://bundler.io/git.html You either need to have .gemspecs in the root of the gem to use it in the way you have described above. Or create a branch/tag and use one of: gem 'my_private_gem', :tag => 'v0.0.1', :git => 'https://username:pwd@bitbucket.org/johnny/my_private_gem.git' gem 'my_private_gem', :branch => 'release-0-0-1', :git => 'https://username:pwd@bitbucket.org/johnny/my_private_gem.git'

Kamen
  • 681
  • 3
  • 10
  • I have `spec.version = MyPrivateGem::Version` in `my_private_gem.gemspec` and `spec.version = MyGem::Version` in `my_gem.gemspec`. I didn't understand your comment about the recursive dependency - it points from `my_gem.gemspec` to `my_private_gem`. I tried tagging and pointing to that, as you suggested, but I'm getting the same response. – Johnny May 08 '15 at 15:07
  • It seems you are doing things right. Just another guess, have you tried to run the application (that includes the gem or an executable from the gem) with `bundle exec` before the command? – Kamen May 08 '15 at 20:51