2

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?

Kevin Buchs
  • 2,520
  • 4
  • 36
  • 55

1 Answers1

3

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
Mr.
  • 9,429
  • 13
  • 58
  • 82
  • Thanks for the answer Mr. There is no Gemfile, just a Gemspec. There is a gems.rb which does define the groups development, test, runtime and includes just one gem each. However, the Gemspec seems to be controlling what `bundle install` is doing, not the gems.rb. – Kevin Buchs Oct 26 '20 at 16:09
  • Thanks. I have now been able to verify that the group *development* is associated with any specification.add_development_dependency statements. It turned out the secondary dependencies were looking like they were overlapping. In addition, the group *runtime* is associated with specification.add_runtime_dependency. – Kevin Buchs Oct 30 '20 at 14:06