Search code examples
gemfilegemfile.lock

Why don't we commit our gemfile.lock for gems?


The Gem Development guide says that the Gemfile.lock file "should always be checked into version control." However, this is NOT true for Gems. For Applications, like your Rails apps, Sinatra apps, etc., it is true. The same does not go for Gems.

For clarification, please see Yehuda's guidance on the roles of .gemspec, Gemfile, and Gemfile.lock files: Clarifying the roles of .gemspec and Gemfile

I don't understand his reason. What if my gem depends on say Rails 3 and is not compatible with Rails 4? Don't I need to then commit my Gemfile.lock which specifies that my gem is only compatible with Rails 3?


Solution

  • This article is a bit dated (~6 years old) although it holds merit in the fact that the gemspec will hold the version controlling. If your gem has a dependency on a specific rails version you would add:

    s.add_dependency "rails", "3.2"
    

    When a user tries to use your gem on rails > 3.2 the dependency kicks in.

    Hope that answers your question. If not, please clarify and I will update this post.