Kevin Buchs
Kevin Buchs

Reputation: 2872

How to work with gemspec add_runtime_dependency and `bundle install`

I have a codebase which has a gemspec file like:

require "rubygems"
::Gem::Specification.new do |specification|
  specification.add_development_dependency "yard", "~> 0.9"
  specification.add_runtime_dependency "dry-validation", "~> 0.13"
end

bundle install will install both dependency types. So I want to just install the runtime dependencies for my CI scripts. I see bundle install --with <group> exists, but I don't have groups. Run interactively, the returned specification has an empty result returned from .groups. I would love to rationalize these two worlds. Must I explicitly add a group for each gem dependency? Does add_runtime_dependency and add_development_dependency even make a difference?

Upvotes: 2

Views: 2527

Answers (1)

Mr.
Mr.

Reputation: 10142

from bundler's documentation

Because we have the gemspec method call in our Gemfile, Bundler will automatically add this gem to a group called “development” which then we can reference any time we want to load these gems with the following line:

Bundler.require(:default, :development)

in your case, if you wish to install all rubygems that are not for development, then try

bundle install --without development

for future bundler version, you can configure it locally (or globally)

bundle config set --local without 'development'

to make it all work, verify that you have a Gemfile in your project, which will look like

# frozen_string_literal: true

source 'https://rubygems.org'

gemspec

Upvotes: 3

Related Questions