例如,给定Gemspec文件:
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "github_stats/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "github_stats"
s.version = GithubStats::VERSION
s.authors = ["Pura Dawid"]
s.email = ["puradawid@gmail.com"]
s.homepage = "https://github.com/puradawid/github_stats"
s.summary = "Project repository model wrapper and statistic fetcher."
s.description = ""
s.license = "MIT"
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
s.add_dependency "rails", "~> 4.1.8"
s.add_runtime_dependency "github_api", "0.12.3"
s.add_development_dependency "sqlite3"
end
为了上帝而Gemfile:
source 'https://rubygems.org'
# Declare your gem's dependencies in github_stats.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
# To use a debugger
#gem 'byebug', group: [:development, :test]
#gem 'github_api', '0.12.3'
group :development do
gem 'byebug'
gem 'mocha'
gem 'guard'
gem 'guard-minitest'
end
group :test do
gem 'rake'
end
github_api
已被注释掉(如果我把它放在这里,它显然有效。)
正如您所看到的,github_api被添加为依赖项(它是一个宝石)。它有效吗?当然不是。输入Bundler.require
会给我:
[<Bundler::Dependency type=:runtime name="github_stats" requirements=">= 0">,
<Bundler::Dependency type=:development name="sqlite3" requirements=">= 0">,
<Bundler::Dependency type=:runtime name="byebug" requirements=">= 0">,
<Bundler::Dependency type=:runtime name="mocha" requirements=">= 0">,
<Bundler::Dependency type=:runtime name="guard" requirements=">= 0">,
<Bundler::Dependency type=:runtime name="guard-minitest" requirements=">= 0">,
<Bundler::Dependency type=:runtime name="rake" requirements=">= 0">]
我看到了这个问题here,但我没有看到一个干净的解决方案。
我有什么问题? add_dependency
add_development_dependency
效果不佳 Bundler version 1.8.4
=> ruby-2.1.5 [ x86_64 ]
,但最后一个根本没有任何意义,即使我也尝试过。
{{1}}
感谢您的帮助,伙计们!
答案 0 :(得分:1)
如果您有兴趣 - issue 1041。阅读之后我才明白,这是标准行为。争论是依靠bundler来要求你的gem依赖是一个坏习惯。您应该明确地要求您的宝石,因为您的宝石应该在没有捆绑器的情况下工作。 Bundler被广泛使用,但不是像红宝石宝石那样的标准。
如果你仍然需要访问bundler所需的宝石,你可以使用这个hack:
Bundler.definition.specs # gives all gems' dependencies