0

My gem depends on nokogiri ~> 1.5.0. I'd like to keep that dependency since this version has less compile-time dependencies and generally installs without problems. nokogiri 1.6.x seems to have more problems installing. So while I'd like to support nokogiri 1.6 if is is already installed, I don't want to make it the default dependency.

So: Prefer nokogiri ~> 1.5.0 but use 1.6 if it's present.

Is it possible to express that as a dependency in my Gemfile or gemspec?

Johannes Fahrenkrug
  • 42,912
  • 19
  • 126
  • 165

1 Answers1

0

You can specify a comma-separated list of version specifiers in your gemspec. They are ANDed together.

spec.add_runtime_dependency "nokogiri", ">= 1.5.0", "< 1.7"

This says that any 1.5.x or 1.6.x version is compatible.

Rubygems doesn't have any notion of a "preferred" version. Bundler and gem will generally try to install the latest version available that satisfies all of the constraints.

See http://guides.rubygems.org/patterns/#declaring-dependencies for details.

Tim Moore
  • 8,958
  • 2
  • 23
  • 34