了解捆绑程序依赖性解析

时间:2019-08-30 23:34:32

标签: ruby-on-rails ruby bundler

我正在将应用程序从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如何解决依赖关系。查看捆绑程序文档,我还没有发现某些冲突的原因。例如,在这种情况下,捆绑程序为什么不接受actionpack 5.2.3:

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

了解这个特殊情况对我真的很有帮助。多谢您的协助。

宝石文件如下:

C:\xampp\php

2 个答案:

答案 0 :(得分:3)

当您查看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限制为Rails 5的有效版本,即3.7.0 ,在您的gemfile中的版本:

  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。这次的宝石版本为quiet_assets宝石,仍然存在一些兼容性错误:

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)

您可以看到它取决于Rails3.x。如果您查看rubygems,您会发现quiet_assets的最新版本也无法在Rails 5上运行。再次,我从Gemfile中删除了gem:

 # gem 'quiet_assets'

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

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

答案 1 :(得分:0)

我建议您通过运行“捆绑软件更新”来更新捆绑软件,而不是运行捆绑软件安装