Is there a need to declare the same dependency on Gemfile and gemspec?

1

I have several engines in my API, all depend on Artemis::Core .

I want to understand the difference between declaring in Gemfile , for example, gem artemis-core :

source 'https://rubygems.org'

gem 'artemis-core', '~> 0.0.1'

gemspec

And declare the same gem in the file gemspec :

$LOAD_PATH.push File.expand_path('../lib', __FILE__)

require 'artemis/support/version'

Gem::Specification.new do |s|
  s.name        = 'artemis-support'
  s.version     = Artemis::Support::VERSION
  s.authors     = ['Secret Name']
  s.email       = ['[email protected]']
  s.summary     = 'Secret summary'

  s.files = Dir['{app,config,db,lib}/**/*', 'Rakefile', 'README.md']

  s.add_dependency 'rails', '~> 5.0.2', '>= 5.0.2'
  s.add_dependency 'artemis-core', '~> 0.0.1'

  s.add_development_dependency 'pg', '~> 0.20'
end

I know that automatically gemspec inherits gems declared in Gemfile .

Is there a special rule for these situations? Thank you.

    
asked by anonymous 17.03.2017 / 22:56

1 answer

1

The gemspec file is rooted in the ruby code, as a boot of the gem, it is the setting that is the dependencies required for the correct operation of the gem.

With the advent of bundler was created the Gemfile which is a super manager of depedence for ruby.

With this your context looks like this:

You have to load your core into gemspec, but gemspec does not have enough functionality to add items like path, github, and so on. Most of it does runtime and development.

In your case, load your gem above the gemspec call in Gemfile with everything you need (path, version, branch) and gemspec to repeat the call with require_dependency 'x'

The gemfile is called before gemspec if the bundle already contains a version of gem core set, gempsec will be able to load it.

Another item that comes as default is that its gemfile arrow everything to: development, which makes it understand something like gems of Gemfile is for an environment: development and gemspec gems are for: production.

    
17.03.2017 / 23:50