1
votes

I have a Ruby project (a Chef cookbook) that I would like to support multiple versions of Ruby on, including the aging Ruby 2.1. However, many of my dependent gems (used only for development & testing) now are placing Ruby version requirements on 2.2 or greater, making my builds fail with errors like:

$ bundle install
Resolving dependencies...
ERROR: your_gem-version requires ruby version >= 2.2.2, which is incompatible with the current version, ruby 2.1.5p273

I've already added a case statement to my Gemfile to require specific gem versions for older Ruby versions, but it's quickly growing out of control as more and more gems are specifying these Ruby version requirements.

Is there a way to get bundler to automatically rule out versions of gems that aren't supported and choose one that is?

Note: I know I can "solve" this with a Gemfile.lock file, but I'd prefer to have my Travis builds pull the latest dependencies so I can catch issues like this. And it's a Chef cookbook, so that lock file is ignored anyways; it's just for developers, and the gems I'm requiring in my Gemfile are just development tools, not runtime requirements.

1
Get comfortable with lockfiles. They are your friend and will save you a lot of pain. You often don't want to automatically upgrade to the latest gem version on everything without looking at the changelogs. If you don't do this you'll instead have a nightmare dealing with random code failures from changed behavior of your dependencies. - Pyrce
From experience, there isnt a uniform error produced when a gem isn't compatible with a ruby version. - max pleaner
Thanks for your comments. After some digging, I found bundler PR 4651 that may offer a long-term solution to my problem, and a workaround until it gets merged in: adding ruby RUBY_VERSION to my Gemfile (requires bundler >= 1.12). - jsmartt

1 Answers

0
votes

bundler may offer a long-term solution to my problem in the future, but for now there is a pretty good workaround solution: adding the following to my Gemfile:

ruby RUBY_VERSION

(requires bundler >= 1.12)

Now my current Ruby version is considered when solving for gem dependencies and my Travis builds are happy.