Does the order of gems in your Gemfile make a difference?

一世执手 提交于 2019-11-28 07:18:16

问题


Is the order in which you list your gems important? Are these two blocks equivalent?

gem 'carrierwave'
gem 'rmagick'

And

gem 'rmagick'
gem 'carrierwave'

回答1:


When you use Bundle.require (which Rails does), Gems are required in the order they appear in the Gemfile. In wasn’t always like this, but has been this way for a while.

Since Carrierwave requires RMagick explicitly when it is needed, I don’t think it should matter in your case; but strictly speaking the two blocks are not equivalent.




回答2:


Bundler doesn't load gem dependencies by the order that you list them*, but it does go by source priority using this criteria:

  1. Explicit path or git options append to a gem dependency, e.g.:

    gem 'some-gem', github: 'somebody/some-gem'
    
  2. Explicitly defined dependencies for gems that are otherwise required implicitly from other gem dependecies, i.e., gem 'actionmailer' gem is implicitly required by gem 'rails'

  3. If you have multiple sources added it will search from last to first.

See http://gembundler.com/v1.3/man/gemfile.5.html#SOURCE-PRIORITY


* Edit: As per Matt's answer, depending on what you're trying to do (or what gems you're loading) the order MIGHT matter. See Even with bundler your gem order can be significant.



来源:https://stackoverflow.com/questions/16724566/does-the-order-of-gems-in-your-gemfile-make-a-difference

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