【问题标题】:Gemfile - separating Production gems from Development gemsGemfile - 将生产 gem 与开发 gem 分开
【发布时间】:2012-10-09 17:48:55
【问题描述】:

所以我知道在 Gemfile 中我可以执行以下操作:

group :development, :test do
  gem 'gem1'
  gem 'gem2'
end

我想要完成的是这样的:

group :production do
  gem 'gem1'
  gem 'gem2'
end

group :development, :test do
  gem 'gem1', :path => '/Documents/Code/gem1/'
  gem 'gem2', :path => '/Documents/Code/gem2/'
end

所以我们的应用程序使用了 2 个我们也在本地开发的 gem。为了缩短在本地机器上开发的时间,我们希望能够将我们的开发环境指向 gem 的本地副本 - 这样它就可以在不需要重新启动我们的 rails 服务器的情况下获取所有更改。否则,我们将不得不重建 gem,重新安装 gem,并在 gem 中的每次开发更改时重新启动 rails。

但是,这样做会给我以下错误:

You cannot specify the same gem twice coming from different sources. You specified that gem1 (>= 0) should come from an unspecfied source and source at /Documents/Code/gem1

我什至尝试过运行bundle install --without production 之类的东西,但我得到了同样的错误。

有谁知道是否可以做我想做的事?

谢谢!

【问题讨论】:

    标签: ruby ruby-on-rails-3 bundler gemfile


    【解决方案1】:

    我认为有一种受支持的方式可以做到这一点,并且有一些技巧可以解决它。

    支持的方式:

    bundle configlocal 选项一起使用,如下所述:http://bundler.io/v1.3/man/bundle-config.1.html

    老套路:

    在生产中使用之前使用环境变量并执行捆绑程序:http://www.cowboycoded.com/2010/08/10/using-2-sources-for-a-gem-in-different-environments-with-bundler/

    在 github 上有一个针对此问题的功能请求,其中包含多个相关问题和大量 cmets:https://github.com/carlhuda/bundler/issues/396

    【讨论】:

    【解决方案2】:

    phoet 链接的github issue 已解决,与支持的方式一致。

    我翻遍了文档,您需要设置配置变量并更新您的 gemfile 以引用分支。

    例如

    编辑您的 Gemfile:

    gem <gem_name>, git: <git_url>, branch: <branch>
    

    在命令行上:

    bundle config local.<gem_name> <local_path_to_gem>
    

    【讨论】:

      【解决方案3】:

      我通过创建一个与原始 Gemfile 相同的新 Gemfile 来解决这个问题,除了目标 gem 的源。然后,在 config/boot.rb 中,我使用了:

      require 'rails' if Rails.env.development? ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../DevGemfile', __FILE__) else ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../ProdGemfile', __FILE__) end

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-06
        • 2015-08-05
        相关资源
        最近更新 更多