Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it still useful to declare development dependencies in a gemspec when using bundler?

I am working on a new Ruby Gem. I am familiar with using Bundler to manage gems:

source "https://rubygems.org"

gemspec

gem 'rspec-rails'

I am familiar with specifying dependencies in a gemspec file:

Gem::Specification.new do |s|
  # ...
  s.add_dependency "rails", "~> 4.1.5"
end

The Gemfile that was generated mentions that I should move my dependency declarations from my Gemfile to my gemspec when I'm ready to release.

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

Why would I want to do this? Why should my gemspec care what gems I'm using in development? What purpose does development_dependency serve that Bundler doesn't already do for me?

like image 769
Andrew Avatar asked Oct 03 '14 18:10

Andrew


People also ask

What does Gemspec file do?

gemspec file is where you provide metadata about your gem to Rubygems. Some required Gemspec attributes include the name, description, and homepage of your gem. This is also where you specify the dependencies your gem needs to run.

What is the use of bundler in rails?

In Rails, bundler provides a constant environment for Ruby projects by tracking and installing suitable gems that are needed. It manages an application's dependencies through its entire life, across many machines, systematically and repeatably. To use bundler, you need to install it.

What do I do with a Gemfile?

Your gemfile is a list of all gems that you want to include in the project. It is used with bundler (also a gem) to install, update, remove and otherwise manage your used gems. These gems belong to development environment and the test environment since they are for testing the application.


2 Answers

To best answer your questions, we should first untangle the concepts of Bundler and Rubygems. I think a great explanation can be found here.

Why Would I Want to [move dependencies from Gemfile to .gemspec]?

Gemfile allows you to specify not only dependencies, but where the dependencies come from. This is useful when you are also working on the dependencies themselves and need to point to a Git repo (or something).

Once work on these dependencies is complete, Rubygem conventions dictate that you move the dependency declaration on these released gems into your .gemspec file. Adding a line gemspec tells Bundler to read from this conventional Rubygems location. If you are working on a gem, and you are not actively developing the gem's dependencies, then all dependencies should be declared in your .gemspec

Why should my gemspec care what gems I'm using in development?

From the docs for add_development_dependency:

Development dependencies aren't installed by default and aren't activated when a gem is required.

A popular example for this Rspec. You should generally declare Rspec as a development dependency for yourself, but not force everyone else to download it when they grab your gem.

like image 65
JohnIV Avatar answered Oct 30 '22 03:10

JohnIV


Note that the comment you cited does not say "development dependencies", it says "dependencies that are in development". Dependencies that are in development commonly include cutting-edge versions of gems that you are installing directly from a Git repo. RubyGems cannot install gems from a Git repo; however, Bundler can. If you are installing cutting-edge versions of gems installed from a source that RubyGems cannot handle (such as a VCS repo), you should list them in your Gemfile instead of the .gemspec file.

like image 26
mipadi Avatar answered Oct 30 '22 02:10

mipadi