6

I have a local gem (enterprise-0.0.1.gem) in a directory '/home/enterprise/pkg'. It has dependency on active_directory gem (v 1.5.5), which was specified in it's enterprise.gemspec file like this :-

gem.add_dependency("active_directory")

In my Application's Gemfile, I add the following line:-

gem 'enterprise', '0.0.1', path => '/home/enterprise/pkg'

When I do

bundle install

from my application's source directory, only the enterprise gem is installed. Hence, I hit runtime errors for the reference to active_directory gem.

But when I do

gem install /home/enterprise/pkg/enterprise-0.0.1.gem

the dependencies are resolved and I can see the active_directory gem in the gem list.

Why is there a discrepancy in the dependency resolution with bundler, and not with rubygems.

Kindly let me know if I need to provide more information about the environment. Ruby: 1.9.2, RubyGems: 1.8.24, Bundler: 1.1.5, rvm: 1.9.2.

My enterprise.gemspec file for reference :-

 # -*- encoding: utf-8 -*-
   require File.expand_path('../lib/enterprise/version', __FILE__)

   Gem::Specification.new do |gem|
      gem.authors       = ["example"]
      gem.email         = ["example@example.com"]
      gem.description   = %q{Enterprise Gem: example}
      gem.summary       = %q{Services: Authentication, Access Control}
      gem.homepage      = "http://example.com"  
      gem.files         = %w[
                       README.md
                       Rakefile
                       Gemfile
                       Gemfile.lock
                       enterprise.gemspec
                       lib/enterprise.rb
                       lib/enterprise/auth_service.rb
                       lib/enterprise/version.rb
                       ]
     gem.executables   = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
     gem.test_files    = gem.files.grep(%r{^(test|spec|features)/})
     gem.name          = "enterprise"
     gem.require_paths = ["lib"]
     gem.version       = Enterprise::VERSION
     gem.add_dependency("active_directory")
   end
neosab
  • 117
  • 1
  • 7

3 Answers3

2

I had the same problem and ended up deleting the Gemfile.lock to resolve the issue.

sailor
  • 7,834
  • 3
  • 26
  • 34
  • Removing the Gemfile.lock entry for my local gem did solve the dependency problem for me as well. – Samuel Apr 01 '15 at 08:01
0

Does your gem, have a Gemfile with the following contents?

source 'https://rubygems.org'

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

Try adding a require in your application gemspec

gem 'enterprise', '0.0.1', path => '/home/enterprise/pkg', :require => "active_directory"
house9
  • 20,359
  • 8
  • 55
  • 61
  • Yes, I do have these in my enterprise gem's Gemfile. Do you require my gemspec file ? – neosab Jul 18 '12 at 23:44
  • No, it does not seem to install the active_directory gem with the :require option. It behaves the same way as before. Only the enterprise gem is installed. – neosab Jul 19 '12 at 22:55
  • I am just curious what is the standard practice for using a custom local gem. Doing a [gem install 'enterprise' & bundle install] everytime I move my application to a production server does not make sense. – neosab Jul 19 '12 at 22:58
  • well I guess I would just add 'active_directory' to the application Gemfile? – house9 Jul 19 '12 at 23:22
  • and you will want to do a `bundle install` every time you deploy to production, it won't pull in any that have not changed - `bundle install --deployment` - guessing you have already been through this documentation: http://gembundler.com/rationale.html – house9 Jul 19 '12 at 23:24
0

Use gem.add_runtime_dependency in your gemspec -- not add_dependency and that ought to require the gem whether you add it to your Gemfile or not.

digitalextremist
  • 5,952
  • 3
  • 43
  • 62
  • Apparently, they are aliases for each other (SO answer: https://stackoverflow.com/a/24334371/1042144, Ruby docs: http://ruby-doc.org/stdlib/libdoc/rubygems/rdoc/Gem/Specification.html#method-i-add_runtime_dependency) – Brian Kung Aug 09 '17 at 15:07