Gemspec 依赖项未使用 Gemfile 加载
Gemspec dependencies are not loaded with Gemfile
例如,给定 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 被添加为依赖项(它是 gem)。它在工作吗?当然不是。输入 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 ]
感谢大家的帮助!
如果您有兴趣 - issue 1041。看完之后我明白了,这是标准行为。争论的焦点是依赖捆绑器来要求您的 gem 依赖项是一种不好的做法。你应该明确要求你的 gems 因为你的 gem 应该在没有捆绑器的情况下工作。 Bundler 被广泛使用但不是像 ruby gems.
这样的标准
如果您仍然需要访问捆绑程序所需的 gems,您可以使用此 hack:
Bundler.definition.specs # gives all gems' dependencies
例如,给定 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 被添加为依赖项(它是 gem)。它在工作吗?当然不是。输入 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 ]
感谢大家的帮助!
如果您有兴趣 - issue 1041。看完之后我明白了,这是标准行为。争论的焦点是依赖捆绑器来要求您的 gem 依赖项是一种不好的做法。你应该明确要求你的 gems 因为你的 gem 应该在没有捆绑器的情况下工作。 Bundler 被广泛使用但不是像 ruby gems.
这样的标准如果您仍然需要访问捆绑程序所需的 gems,您可以使用此 hack:
Bundler.definition.specs # gives all gems' dependencies