rails up gradeに伴うgemの依存関係の修正(4.2.8 -> 5.0.0.1)
状況
herokuにデプロイしているアプリのpostgres9.6がEOLに。
postgresのversion upに伴い互換性の問題よりrailsを4.2.8から5にupgradeすることになった。
様々な記事を読み漁り、まずrails version up に伴い発生するgemの互換性問題の解決に取り組むが、うまく行かない。
一気にgemをupdateしようとするのが原因か、bundle update が通りません。
vrsions
- ruby 2.5.3
- rails 4.2.8 --> 5.0.0.1
- bundler 1.17.3
gemfileの現状
source 'https://rubygems.org'
ruby "2.5.3"
-gem 'rails', '4.2.8'
+gem 'rails', '5.0.0.1'
gem 'clockwork'
-gem 'coffee-rails', '~> 4.1.0'
+gem 'coffee-rails'#, '~> 4.1.0'
gem 'date_select_separator'
gem 'default_value_for'
gem 'devise'
gem 'devise-i18n'
gem 'enumerize'
gem 'haml-rails'
gem 'hamlit'
-gem 'jbuilder', '~> 2.0'
+gem 'jbuilder'
gem 'jquery-rails'
-gem 'pg', '~> 0.18.2'
+gem 'pg'#, '~> 0.18.2'
gem 'rails_config'
gem 'config', github: 'railsconfig/config'
-gem 'rails_script', '~> 0.6.1'
+gem 'rails_script'#, '~> 0.6.1'
gem 'restforce'
gem 'salesforce_bulk_api'
-gem 'sass-rails', '~> 6'
-gem 'sdoc', '~> 0.4.0', group: :doc
+gem 'sass-rails'
+gem 'sdoc'#, '~> 0.4.0', group: :doc
gem 'turbolinks'
-gem 'uglifier', '>= 1.3.0'
+gem 'uglifier'
gem 'valid_email'
gem 'rinku'
gem 'metamagic'
end
group :development do
gem 'letter_opener'
- gem 'letter_opener_web', '~> 1.2.0'
- gem 'web-console', '~> 2.0'
+ gem 'letter_opener_web'#, '~> 1.2.0'
+ gem 'web-console'#, '~> 2.0'
gem 'better_errors'
gem 'binding_of_caller'
+ gem 'rails-erd'
end
gem 'rails_12factor', group: %i(production staging)
-group :development do
- gem 'rails-erd'
-end
試みたこと
railsのversionを変更しbundle update rails
$ bundle update rails
Fetching source index from https://rails-assets.org/
Fetching source index from https://rubygems.org/
Resolving dependencies....
Bundler could not find compatible versions for gem "actionpack":
In Gemfile:
haml-rails was resolved to 1.0.0, which depends on
actionpack (>= 4.0.1)
rails (= 5.0.0.1) was resolved to 5.0.0.1, which depends on
actionpack (= 5.0.0.1)
devise was resolved to 4.8.0, which depends on
responders was resolved to 2.4.1, which depends on
actionpack (< 6.0, >= 4.2.0)
rspec-rails was resolved to 4.1.2, which depends on
actionpack (>= 4.2)
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (= 5.0.0.1)
letter_opener_web was resolved to 1.2.3, which depends on
rails (>= 3.2)
metamagic was resolved to 3.1.7, which depends on
rails (>= 3.0.0)
Bundler could not find compatible versions for gem "railties":
In Gemfile:
coffee-rails was resolved to 4.1.1, which depends on
railties (< 5.1.x, >= 4.0.0)
devise was resolved to 4.8.0, which depends on
railties (>= 4.1.0)
dotenv-rails was resolved to 2.7.6, which depends on
railties (>= 3.2)
haml-rails was resolved to 1.0.0, which depends on
railties (>= 4.0.1)
jquery-rails was resolved to 4.4.0, which depends on
railties (>= 4.2.0)
quiet_assets was resolved to 1.1.0, which depends on
railties (< 5.0, >= 3.1)
rails (= 5.0.0.1) was resolved to 5.0.0.1, which depends on
railties (= 5.0.0.1)
devise was resolved to 4.8.0, which depends on
responders was resolved to 2.4.1, which depends on
railties (< 6.0, >= 4.2.0)
rspec-rails was resolved to 4.1.2, which depends on
railties (>= 4.2)
sass-rails was resolved to 6.0.0, which depends on
sassc-rails (>= 2.1.1, ~> 2.1) was resolved to 2.1.2, which depends on
railties (>= 4.0.0)
web-console was resolved to 2.3.0, which depends on
railties (>= 4.0)
上記のメッセージからupdateが必要なパッケージをまとめてbundle update
$ bundle update actionpack rails railties haml-rails devise rspec-rails letter_opener_web metamagic coffee-rails dotenv-rails jquery-rails
quiet_assets sass-rails web-console actionmailer rails_script quiet_assets factory_bot_rails
Bundler could not find compatible versions for gem "actionmailer":
In Gemfile:
letter_opener_web was resolved to 1.4.0, which depends on
actionmailer (>= 3.2)
rails (= 5.0.0.1) was resolved to 5.0.0.1, which depends on
actionmailer (= 5.0.0.1)
Bundler could not find compatible versions for gem "actionpack":
In Gemfile:
haml-rails was resolved to 1.0.0, which depends on
actionpack (>= 4.0.1)
rails (= 5.0.0.1) was resolved to 5.0.0.1, which depends on
actionpack (= 5.0.0.1)
rspec-rails was resolved to 3.9.1, which depends on
actionpack (>= 3.0)
Bundler could not find compatible versions for gem "coffee-rails":
In Gemfile:
coffee-rails
rails_script was resolved to 2.0.4, which depends on
coffee-rails (>= 4.0.0)
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (= 5.0.0.1)
jquery-rails was resolved to 0.1.2, which depends on
rails (~> 3.0.0.rc)
Bundler could not find compatible versions for gem "railties":
In Gemfile:
jquery-rails was resolved to 1.0.19, which depends on
railties (~> 3.0)
rails (= 5.0.0.1) was resolved to 5.0.0.1, which depends on
railties (= 5.0.0.1)
まだ怒られる。
上記のメッセージのにあるパッケージは、全てbundle update
に記載していたはずなのに。
なにかお気づきの点があれば、ご教授お願いいたします。
追記
下記の箇所のjquery-rilas要求するrailties versionに矛盾が起きていることに気づきました。
Gemfile.lockを確認すると下記の記載がありました。
私の理解ではjquery-rails was resolved to 0.1.2
この記述の意味は、
「Gemlock.fileによりjquery-rails のバージョンは0.1.2に指定されている」です。
しかし、上のjquery-railsは0.1.2 下は1.0.19、gemfile.lockは4.4.0で、おかしなことになっています。
私の解釈は間違っているのでしょうか。
また、bundle update実行時、railtiesのdependency は~> 3.0
ですが、
Gemfile.lockやrubygems.orgには、railties (>= 4.2.0)
このように記載されています。
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (= 5.0.0.1)
jquery-rails was resolved to 0.1.2, which depends on
rails (~> 3.0.0.rc)
Bundler could not find compatible versions for gem "railties":
In Gemfile:
jquery-rails was resolved to 1.0.19, which depends on
railties (~> 3.0)
rails (= 5.0.0.1) was resolved to 5.0.0.1, which depends on
railties (= 5.0.0.1)
jquery-rails (4.4.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
追記2
試しにgem jquery-rails
をコメントアウト。
メッセージが変化。
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (= 5.0.0.1)
quiet_assets was resolved to 1.0.0, which depends on
rails (~> 3.1)
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 (= 5.0.0.1) was resolved to 5.0.0.1, which depends on
railties (= 5.0.0.1)
調べてみると、gem 'quiet_assets'
はrails5に取り込まれたらしい。
なので、gem 'quiet_assets'
をコメントアウトし、再びbundle update
エラーメッセージより一部抜粋
Bundler could not find compatible versions for gem "websocket-driver":
In snapshot (Gemfile.lock):
websocket-driver (= 0.7.5)
In Gemfile:
rails (= 5.0.0.1) was resolved to 5.0.0.1, which depends on
actioncable (= 5.0.0.1) was resolved to 5.0.0.1, which depends on
websocket-driver (~> 0.6.1)
poltergeist was resolved to 1.18.1, which depends on
websocket-driver (>= 0.2.0)
websocket-driver
のupdateが必要そうなので、bundle updateに書き加える。
$ bundle update actionpack rails railties ml-rails devise rspec-rails letter_opener_web metamagic coffee-rails dotenv-rails quiet_asse sassc-rails web-console actionmailer rails_script quiet_assets factory_bot_rails websocket-iver
The git source `git://github.com/railsconfig/config.git` uses the `git` protocol, which tranits data without encryption. Disable this warning with `bundle config git.allow_insecure tru, or switch to the `https` protocol to keep your data secure.
Fetching gem metadata from https://rails-assets.org/..
Fetching gem metadata from https://rails-assets.org/..
Fetching gem metadata from http://rubygems.org/.............
Fetching gem metadata from https://rails-assets.org/..
Fetching gem metadata from https://rails-assets.org/..
Fetching gem metadata from http://rubygems.org/..
Resolving dependencies.......
Using rake 13.0.6
Using concurrent-ruby 1.1.9
Using i18n 0.9.5
Using minitest 5.14.4
Using thread_safe 0.3.6
Using tzinfo 1.2.9
Fetching activesupport 5.0.0.1 (was 4.2.8)
ArgumentError: wrong number of arguments (given 4, expected 1)
An error occurred while installing activesupport (5.0.0.1), and Bundler cannot
continue.
Make sure that `gem install activesupport -v '5.0.0.1'` succeeds before bundling.
In Gemfile:
metamagic was resolved to 3.1.7, which depends on
rails was resolved to 5.0.0.1, which depends on
actioncable was resolved to 5.0.0.1, which depends on
actionpack was resolved to 5.0.0.1, which depends on
actionview was resolved to 5.0.0.1, which depends on
rails-dom-testing was resolved to 2.0.3, which depends on
activesupport
gem install activesupport -v '5.0.0.1'
試すと
$ gem install activesupport -v '5.0.0.1'
ERROR: While executing gem ... (ArgumentError)
wrong number of arguments (given 4, expected 1)
調べると、このエラーはrubygemsのバージョンが原因らしい。
rubygemsのバージョンを確認
$ gem env version
2.7.6
rubyのversinは2.5.3だから、rubygemsのversionは2.7.6以降でないといけないが、要件は満たしている。