The article I published about using Bundler to manage your gem’s gem dependencies turned out a bit different than I thought. I started writing it because I had a problem with Bundler’s add_bundler_dependencies
method and I wanted to propose a better way to handle this.
So I went to Bundler’s amazing little website to read up the nasty feature, but it was gone. After looking around for a second, I found the new “Using Bundler with Rubygem gemspecs” page and realized a lot had changed since everybody got excited about add_bundler_dependencies
at Railsconf.
I ended up writing a cheerful article about how awesome Bundler was, since my biggest annoyance had been destroyed. Now, a couple of weeks later, this article about add_bundler_dependencies
started to get mentioned again. Please allow me to explain why I think you should stop using it.
Why?
If you don’t know, add_bundler_dependencies
allows you to make your .gemspec
get its dependencies from your Gemfile
:
# .gemspec
require 'bundler'
Gem::Specification.new do |s|
s.add_bundler_dependencies
end
A very convenient way not to have to specify your dependencies twice, right? The problem with this is that you just added Bundler to your gem’s dependencies.
This feels totally backwards, since the .gemspec
file should be the one specifying Gem dependencies. If you ask me, getting them from the Gemfile
instead and adding a dependency is wrong. Bundler should only be needed when you want to do something with the Gemfile
, the .gemspec
— and the rest of the gem — should work without it.
Gemfiles reading .gemspecs
The new implementation turns this all around and allows you to let your Gemfile
read dependencies from your .gemspec
, so you don’t need Bundler to install it anymore. It’s a matter of simply throwing gemspec
into your Gemfile
:
# Gemfile
gemspec
Please, let’s start using that one now. It’s prettier, it makes more sense and there’s a reason add_bundler_dependencies
isn’t mentioned on the Bundler website anymore.
What do you think about a deprecation warning when still using Oh, it’ll throw a deprecation warning too.add_bundler_dependencies
? @wycats? @carllerche? Anyone?