Gemfile - separating Production gems from Development gems

南楼画角 提交于 2019-12-22 09:07:32

问题


So I know that in a Gemfile I can do something like this:

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

What I am looking to accomplish is something like this:

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

So our application uses 2 gems that we also develop locally. In order to improve time while developing on our local machines, we want to be able to point our dev environments to the local copies of the gems - this way it picks up all changes without needing to restart our rails server. Otherwise we would have to rebuild the gem, re-install the gem, and restart rails with every development change in the gem.

However, doing this gives me the following error:

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

I have tried even running something like bundle install --without production and I get the same error.

Does anyone know if it IS possible to do what I would like to do?

Thanks!


回答1:


i think that there is a supported way to do it and some hacks to work around it.

supported way:

use bundle config with the local option as described here: http://bundler.io/v1.3/man/bundle-config.1.html

hacky way:

use env vars and execute bundler before using in production: http://www.cowboycoded.com/2010/08/10/using-2-sources-for-a-gem-in-different-environments-with-bundler/

there is a feature-request for this problem on github with several related issues and lots of comments: https://github.com/carlhuda/bundler/issues/396




回答2:


the github issue phoet linked to is resolved, and is consistent with the supported way.

I dug around through the docs, you'll need to set the config variable and updated your gemfile to reference the branch as well.

e.g.

edit your Gemfile:

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

on command line:

bundle config local.<gem_name> <local_path_to_gem>



回答3:


I solved this by creating a new Gemfile that's identical to the original except for the target gem's source. Then, in config/boot.rb, I used:

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



来源:https://stackoverflow.com/questions/12805569/gemfile-separating-production-gems-from-development-gems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!