ruby gemspec中的依赖

问题的来源--sidekiq 4.1.3中的提交中有如下这么一个commit

sidekiq依赖于sinatra,在这个提交中,sinatra由development_dependency提升为dependency, 导致升级sidekiq后,bundle install 正常,当时启动或者重启sidekiq失败,发现sinatra依赖1.4.x版本。

翻遍了个整个网络,找到如下两篇文件
github中关于dependency的讨论还是挺多的(囧,文章好长)
rubygems官方说明

首先看一下sidekiq的gemspec文件

# -*- encoding: utf-8 -*-

require File.expand_path('../lib/sidekiq/version', __FILE__)

Gem::Specification.new do |gem|

gem.authors = ["Mike Perham"]

gem.email = ["[email protected]"]

gem.summary = "Simple, efficient background processing for Ruby"

gem.description = "Simple, efficient background processing for Ruby."

gem.homepage = "http://sidekiq.org"

gem.license = "LGPL-3.0"

gem.executables = ['sidekiq', 'sidekiqctl']

gem.files = `git ls-files | grep -Ev '^(myapp|examples)'`.split("\n")

gem.test_files = `git ls-files -- test/*`.split("\n")

gem.name = "sidekiq"

gem.require_paths = ["lib"]

gem.version = Sidekiq::VERSION

gem.add_dependency 'redis', '~> 3.2', '>= 3.2.1'

gem.add_dependency 'connection_pool', '~> 2.2', '>= 2.2.0'

gem.add_dependency 'concurrent-ruby', '~> 1.0'

gem.add_dependency 'rack-protection', '>= 1.5.0'

gem.add_development_dependency 'redis-namespace', '~> 1.5', '>= 1.5.2'

gem.add_development_dependency 'minitest', '~> 5.7', '>= 5.7.0'

gem.add_development_dependency 'rake', '~> 10.0'

gem.add_development_dependency 'rails', '>= 3.2.0'

end

该gemspec中指定了runtime dependency和development dependency。

runtime dependency有redis, connection_pool, concurrent-ruby, rack-protection这些都是sidekiq运行时所必需的
development dependency有redis-namepace, minitest, rake, rake, rails是sidekiq build(启动)以及test所需要的

那么gem install安装的时候如何安装所有的依赖呢?

可用过gem install --dev sidekiq 或者gem install --development-all sidekiq, 前者会安装development dependency, 后者会安装包括依赖的依赖。development dependency默认不会被安装,并且当gem被require的时候,它们不会被激活(加载)

你可能感兴趣的:(ruby gemspec中的依赖)