gpt4 book ai didi

ruby-on-rails - Gemspec 依赖项未使用 Gemfile 加载

转载 作者:行者123 更新时间:2023-12-05 05:25:50 27 4
gpt4 key购买 nike

例如,给定 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 .看完之后我明白了,这是标准行为。争论的焦点是依赖 bundler 来要求你的 gem 依赖是一种不好的做法。您应该明确要求您的 gem ,因为您的 gem 应该在没有 bundler 的情况下工作。 Bundler 被广泛使用,但不像 ruby​​ gems 那样是一个标准。

如果您仍然需要访问 bundler 所需的 gem,您可以使用这个 hack:

Bundler.definition.specs # gives all gems' dependencies

关于ruby-on-rails - Gemspec 依赖项未使用 Gemfile 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29620076/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com