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

Asked

Viewed 70 times

1

I have several Engines in my API, all have as a dependency Artemis::Core.

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

source 'https://rubygems.org'

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

gemspec

And declare in 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 the gemspec inherits the Gems declared in Gemfile.

Is there any special rule for such situations? Thank you.

  • This influences the dependencies that will be installed by the host?

  • Making some tests I understood better, for this example what goes to the Gemfile will be used to develop Gem, and what goes to the gemspec shall be used to rotate the Gem.

1 answer

1


The gemspec file it is rooted in the ruby code, as a Gem boot, is in it the 'Setting' of are the dependencies required for the correct functioning of Gem.

With the advent of the bundler Gemfile has been created which is a super function manager for ruby.

With that your context is as follows:

You have to load your core into gemspec, but gemspec doesn’t have enough functionality to aggregate items like path, github, etc.. At most it differentiates Runtime and Development.

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

gemfile is called before gemspec if Bundle already contains a version of Gem core set, gempsec will be able to load it.

Another item that comes as default is that your gemfile arrow everything to :Velopment, which gives to understand something like Gemfile’s Gems is for an enviroment :Velopment and gemspec’s Gems are for :Production.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.