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:[email protected]/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?

6

1 Answer 1

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:[email protected]/johnny/my_private_gem.git' gem 'my_private_gem', :branch => 'release-0-0-1', :git => 'https://username:[email protected]/johnny/my_private_gem.git'

2
  • 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 8, 2015 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 8, 2015 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.