Donato Donato - 1 year ago 108
Ruby Question

Why didn't bundler install the dependency?

My understanding of bundler is that when you add a Gem to the Gemfile, bundler will automatically install all its dependencies when you run

bundle install

I am creating a gem. In my gemspec, I specified the following requirements:

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "eventmachine", "~> 1.0.4"
spec.add_development_dependency "em-synchrony"
spec.add_development_dependency "rspec"

Bundler completed all the installations just fine. When I look at Gem.lock, I notice the following:

em-synchrony (1.0.5)
eventmachine (>= 1.0.0.beta.1)

Notice no MySQL dependency for em-synchrony. When I launch irb, and I require my gem, I get the following error:

> require 'my_gem'
RuntimeError: Missing EM-Synchrony dependency: gem install mysql2

Why didn't bundler install the mysql2 gem automatically?

Answer Source

em-synchrony does not depend on mysql2. It is merely a supported client, one of several:

Indeed, looking at em-synchrony's gemspec reveals only one dependency eventmachine:

It is, however, a development dependency of em-synchrony as listed in the development group in its Gemfile. These dependencies won't get installed for you.

You'll have to manually include mysql2 yourself.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download