了解捆绑器依赖解析

Understanding bundler dependency resolution

我正在将一个应用程序从 Rails 4 迁移到 Rails 5,但由于依赖冲突,我正在努力获得一个完整的包。我对为什么这是一个问题感到有点困惑,因为我不完全理解为什么捆绑器无法解决依赖关系。

在这种情况下,我在 Windows。我已经使用 BitNami Ruby 安装了 Ruby 2.5.5 并安装了 Rails 5.2.3。我删除了 Gemfile.lock 和 运行 捆绑安装。 Gemfile 指定 Ruby 2.5.5 和 Rails 5.2.3。没有其他 gem 指定版本要求。捆绑包在 1.17.3.

我对这个问题以及其他转换这个特定应用程序的兴趣是为了更好地理解 bundle 如何解决依赖关系。查看bundler文档,我还没有发现一些冲突的原因。例如,在这种情况下,为什么捆绑器不接受 actionpack 5.2.3:

Bundler could not find compatible versions for gem "actionpack":
  In Gemfile:
    jquery-datatables-rails x64-mingw32 was resolved to 3.4.0, which depends on
      actionpack (>= 3.1) x64-mingw32

    rails (= 5.2.3) x64-mingw32 was resolved to 5.2.3, which depends on
      actionpack (= 5.2.3) x64-mingw32

    rspec-rails x64-mingw32 was resolved to 3.8.2, which depends on
      actionpack (>= 3.0) x64-mingw32

    simple_form x64-mingw32 was resolved to 4.1.0, which depends on
      actionpack (>= 5.0) x64-mingw32

    rails (= 5.2.3) x64-mingw32 was resolved to 5.2.3, which depends on
sprockets-rails (>= 2.0.0) x64-mingw32 was resolved to 3.2.1, which
depends on
        actionpack (>= 4.0) x64-mingw32

了解这个特殊案例对我很有帮助。非常感谢你的帮助。

Gemfile如下:

source 'https://rubygems.org'
ruby '2.5.5' 
gem 'rails', '5.2.3'
gem 'aasm'
gem 'active_model-errors_details'
gem 'acts_as_tenant'
gem 'acts_as_xlsx'
gem 'addressable'
gem 'autoprefixer-rails'
gem 'awesome_print'
gem 'aws-sdk'
gem 'aws-sdk-core'
gem 'aws-sdk-resources'
gem 'axlsx'
gem 'axlsx_rails'
gem 'better_delayed_job_web'
gem 'bindex'
gem 'bootstrap-sass'
gem 'delayed_job'
gem 'delayed_job_active_record'
gem 'exception_notification'
gem 'exception_notification-rake'
gem 'figaro'
gem 'ffi'
gem 'font-awesome-sass'
gem 'forgery'
gem 'htmlentities'
gem 'jquery-datatables-rails'
gem 'jquery-rails'
gem 'jquery-turbolinks'
gem 'jquery-ui-rails'
gem 'json_pure'
gem 'logging'
gem 'nokogiri'
gem 'paloma'
gem 'pg'
gem 'phony'
gem 'phony_rails'
gem 'rake'
gem 'redis'
gem 'responders'
gem 'robocop'
gem 'rolify'
gem 'roo'
gem 'roo-xls'
gem 'rubyzip'
gem 'sass'
gem 'sass-rails'
gem 'simple_form'
gem 'smarter_csv'
gem 'sorcery'
gem 'spreadsheet'
gem 'sprockets'
gem 'sprockets-rails'
gem 'turbolinks'
gem 'twilio-ruby'
gem 'tzinfo-data'
gem 'uglifier'
gem 'will_paginate'
group :production, :staging do
  gem 'rails_12factor'
  platforms :ruby do
    gem 'unicorn'
  end
end
group :development do
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'brakeman'
  gem 'bullet'
  gem 'coffee-rails-source-maps'
  gem 'meta_request'
  gem 'require_reloader'
  gem 'quiet_assets'
  gem 'rails_layout'
  gem 'rubocop'
  gem 'web-console'
end
group :development, :test do
  gem "faker"
  gem "squasher"
  gem 'fabrication'
  gem 'factory_bot_rails'
  gem 'letter_opener'
  gem 'method_source'
  gem 'rspec'
  gem 'rspec-collection_matchers'
  gem 'rspec-core'
  gem 'rspec-expectations'
  gem 'rspec-mocks'
  gem 'rspec-rails'
  gem 'rspec-support'
  gem 'thin'
end
group :test do
  gem "launchy"
  gem 'capybara'
  gem 'chromedriver-helper'
  gem 'database_cleaner'
  gem 'email_spec'
  gem 'json_spec'
  gem 'mocha'
  gem 'selenium-webdriver'
  gem 'shoulda-callback-matchers'
  gem 'shoulda-matchers'
end

我建议您通过 运行ning "bundle update" 比 运行 bundle install

更新您的包

当您查看 bundle install 的完整输出时,它很长:

Bundler could not find compatible versions for gem "actionpack":
  In Gemfile:
    jquery-datatables-rails was resolved to 3.4.0, which depends on
      actionpack (>= 3.1)

    rails (= 5.2.3) was resolved to 5.2.3, which depends on
      actionpack (= 5.2.3)

    rspec-rails was resolved to 3.8.2, which depends on
      actionpack (>= 3.0)

    simple_form was resolved to 4.1.0, which depends on
      actionpack (>= 5.0)

    rails (= 5.2.3) was resolved to 5.2.3, which depends on
      sprockets-rails (>= 2.0.0) was resolved to 3.2.1, which depends on
        actionpack (>= 4.0)

Bundler could not find compatible versions for gem "activemodel":
  In Gemfile:
    rails (= 5.2.3) was resolved to 5.2.3, which depends on
      activemodel (= 5.2.3)

    web-console was resolved to 4.0.1, which depends on
      activemodel (>= 6.0.0)

Bundler could not find compatible versions for gem "activerecord":
  In Gemfile:
    acts_as_xlsx was resolved to 1.0.6, which depends on
      activerecord (>= 2.3.9)

    better_delayed_job_web was resolved to 1.3.12, which depends on
      activerecord (> 3.0.0)

    delayed_job_active_record was resolved to 4.1.4, which depends on
      activerecord (>= 3.0, < 6.1)

    rails (= 5.2.3) was resolved to 5.2.3, which depends on
      activerecord (= 5.2.3)

Bundler could not find compatible versions for gem "activesupport":
  In Gemfile:
    active_model-errors_details was resolved to 1.1.1, which depends on
      activesupport

    delayed_job was resolved to 4.1.8, which depends on
      activesupport (>= 3.0, < 6.1)

    exception_notification-rake was resolved to 0.3.0, which depends on
      exception_notification (~> 4.2.0) was resolved to 4.2.2, which depends on
        activesupport (>= 4.0, < 6)

    rails (= 5.2.3) was resolved to 5.2.3, which depends on
      activesupport (= 5.2.3)

    rspec-rails was resolved to 3.8.2, which depends on
      activesupport (>= 3.0)

    shoulda-matchers was resolved to 4.1.2, which depends on
      activesupport (>= 4.2.0)

    rails (= 5.2.3) was resolved to 5.2.3, which depends on
      sprockets-rails (>= 2.0.0) was resolved to 3.2.1, which depends on
        activesupport (>= 4.0)

Bundler could not find compatible versions for gem "axlsx":
  In Gemfile:
    axlsx

    acts_as_xlsx was resolved to 1.0.6, which depends on
      axlsx (>= 1.0.13)

    axlsx_rails was resolved to 0.5.2, which depends on
      axlsx (>= 2.0.1)

Bundler could not find compatible versions for gem "exception_notification":
  In Gemfile:
    exception_notification

    exception_notification-rake was resolved to 0.3.0, which depends on
      exception_notification (~> 4.2.0)

Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    rails (= 5.2.3)

    acts_as_tenant was resolved to 0.4.4, which depends on
      rails (>= 4.0)

    axlsx_rails was resolved to 0.1.5, which depends on
      rails (>= 3.1)

可能太长了,输出中有很多噪音。但是,如果您尝试深入挖掘,您会发现一些有趣的行:

    web-console was resolved to 4.0.1, which depends on
      activemodel (>= 6.0.0)

这意味着 web-console v4.0.1 至少需要 activemodel gem 6.0.0,因此您应该将 web-console 限制为 [=53= 的有效版本] 5,即 3.7.0,您 gem 文件中的版本:

  gem web-console, '< 4.0'

现在,当您再次尝试 运行 bundle install 时,它会再次显示类似的错误,但会有一些差异。在新输出中,您会发现以下差异:

    active_model-errors_details was resolved to 1.1.1, which depends on
      activemodel (>= 4.0, < 5.0.0.alpha)

这意味着active_model-errro_details不能运行和Rails 5.根据Rubygems,这个gem不能运行 和 Rails 5.2.3 见 https://rubygems.org/gems/active_model-errors_details,所以我在 gemfile:

中注释掉了
# gem 'active_model-errors_details'

并再次尝试 运行 bundle install。 gem版本还有一些兼容性错误这次是quiet_assets gem:

Bundler could not find compatible versions for gem "railties":
  In Gemfile:
    quiet_assets was resolved to 1.0.1, which depends on
      railties (~> 3.1)

你可以看到它依赖于 Rails 3.x。如果你查看 rubygems,你会发现即使是最新版本的 quiet_assets 也不能是 运行 和 Rails 5. 我再次删除了gem 来自 Gemfile:

 # gem 'quiet_assets'

现在,当您尝试 运行 bundle install 时,所有 gems 的版本问题都将得到解决,并且 gems 将被成功安装。

有点乱,错误输出中有很多噪音,但仔细阅读就会发现问题所在。