1.3' -6ren">
gpt4 book ai didi

ruby-on-rails - 自定义 gem 依赖项未添加到 Gemfile.lock?

转载 作者:太空宇宙 更新时间:2023-11-03 16:41:00 24 4
gpt4 key购买 nike

我写了一个 gem。在我的 Gem 的 gemspec 文件中,我有这样的东西:

 spec.add_development_dependency "aws-sdk-mturk", '~> 1.3'

在我的一个 Gem 文件中,我有:

require 'aws-sdk-mturk'

此 gem 未发布到 ruby​​gems.org。它是我私有(private) git 帐户上的私有(private) gem。所以我想将它添加到我的 Rails 项目中,所以我在 Gemfile 中这样做了:

gem "my_gem", git: "https://git.mygitlab.net/myuser/mygem.git", branch: "master"

我注意到当我运行 bundle install 然后运行 ​​bundle update --source mygem 时,在 Gemfile.lock 中它没有显示任何依赖项,包括 aws -sdk-mturk.

所以当我尝试运行 Rails 应用程序时,我得到了这个错误:

gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require': cannot load such file -- aws-sdk-mturk (LoadError)

bundler/Rails 应用程序何时不读取我的私有(private) gem 的 .gemspec 依赖项?

最佳答案

如果您的代码在运行时需要其他 gem,请将 add_development_dependency 更改为 add_runtime_dependency

引自 https://guides.rubygems.org/patterns/#declaring-dependencies

Runtime vs. development

RubyGems provides two main “types” of dependencies: runtime and development. Runtime dependencies are what your gem needs to work (such as rails needing activesupport).

Development dependencies are useful for when someone wants to make modifications to your gem. When you specify development dependencies, another developer can run gem install --dev your_gem and RubyGems will grab both sets of dependencies (runtime and development). Typical development dependencies include test frameworks and build systems.

关于ruby-on-rails - 自定义 gem 依赖项未添加到 Gemfile.lock?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51296683/

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