Attention gem authors

TL;DR: if your gem has dependencies on other gems, make sure it requires them, because Bundler won’t hold your hand any more.

Gem authors: if you’re using your gem primarily in Bundler-managed environments and you have runtime dependencies on other gems, you may have a hidden bug which Bundler 1.1 (as it stands) will reveal. Read on to find out how to fix it.

Given a gem depending on capistrano with a single file in its libs, looking something like this:

And a gemspec declaring a dependency on capistrano:

When you call Bundler.require in your app with this gem in the Gemfile, Bundler 1.0 will make sure to require capistrano first. Bundler 1.1, on the other hand, will not. This causes the application using your gem to crash out with ‘uninitialized constant Capistrano’. To resolve, you should do what you should have done in the first place, and explicitly require capistrano in your gem’s lib files. This has the added advantage of not requiring your users either to use Bundler or explicitly require their dependencies themselves.

blog comments powered by Disqus