Search code examples
rubyrubygemsbundlergemspecs

Private gem in gemspec


I need private gem in my gem and gemspec dependency can't contains git repository.

So I stared my private server with geminabox and added source to my gemfile.

When I bundle install or install gem called "core", then is installed gem from rubygems instead from my repository.

How can I specify my own gem in gemspec?


Solution

  • In the end if they release a greater version than you and you bundle update it, bundle will get their new version so be really careful.

    Change the order of your source lines in your Gemfile, the priority is taken in reverse order:

    source 'https://rubygems.org'
    source 'http://yourgeminaboxhost/gems'
    

    Still, make sure you use a version specification that will resolve to your released gem version:

    gem 'core', '0.0.1'    # If both gems have that version, it will get the one
                           # in the last sourced gem server
    gem 'core', '~> 0.0.1' # This will get the greatest version greater than 0.0.1 and 
                           # lower than 0.1.0 in any of the sources so be careful
                           # because the one in rubygems is 0.0.6 > 0.0.1
    

    The other option would be to increase your version number to be greater than theirs and specify it in your gemfile, let's say you release your gem as 1.0.0:

    gem 'core', '~> 1.0.0' # This will get your releases until they start to 
                              # release a version greater than 1.0.0
    

    The last resort would be to change the name, probably namespacing it since there is always the risk of getting a version from rubygems.org if someone releases a greater version that matches your version specification in the Gemfile.