Reputation: 6451
I'm new to rails -- what are the pros and cons are of specifying the exact (current) gem versions?
Here are the gems I have in my engine:
s.add_dependency "haml-rails"
s.add_dependency "strip_attributes"
s.add_dependency "devise"
s.add_dependency "daemons"
s.add_dependency "delayed_job_active_record"
s.add_dependency "gravatar_image_tag"
Does adding a version ensure a future version of the gem doesn't break the app?
But wouldn't that mean your won't get any bug fixes?
Upvotes: 1
Views: 120
Reputation: 1227
Pros to specifying the versions of your gems:
Gemfile.lock
only gets altered for the new gem. If your versions aren't made explicit, they might accidentally alter multiple gem installs. You might be working on some feature, and accidentally include a gem update that you didn't notice. It's true that you should catch this in code review, but you might not. This sort of thing especially often, especially to juniors, if gem versions aren't explicit.Cons to specifying the versions of your gems:
Gemfile.lock
regularly, you will always have up-to-date gems, which can have many benefits including added functionality from the gems as well as improved security.Gemfile.lock
file are supposed to have a lot of the responsibility of managing gem versions. From this point of view, devs should "let the tool do the work" instead of micromanaging gem versions themselves.The best of both worlds may be to specify the versions explicitly, and then use a tool for automatically updating your dependencies when possible, so that the gem updates end up being separate commits. This way, if they cause bugs or break tests, the cause is easier to track down. Some examples of tools like this are gemnasium
and dependabot
. If you are also pulling in javascript libraries, this would be a good practice to apply there as well.
In response to your specific questions:
Upvotes: 0
Reputation: 5343
Your Gemfile.lock
will record the versions, and lock them for you.
Use it - with bundler. I currently must maintain a Rails 2.3 app, and I frequently must fend off the latest versions of gems that think they have been invited in.
Upvotes: 0
Reputation: 1101
It is considered to be a best practice to follow semantic versioning . To sum it up minor versions only contain bug fixes and don't change the API, so if you want to get best of both worlds use something like
gem 'library', '~> 2.2'
this way you will get highest 2.2 version (e.g. 2.2.3) with all the bug fixes and no breaking changes.
Upvotes: 2