I have still rake/rdoctask deprecated warning

2019-03-12 05:39发布

问题:

I've made bundle update a now I have still rake/rdoctask deprecated warning after running rake command.

WARNING: 'require 'rake/rdoctask'' is deprecated.  Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
    at /home/cheetah/.rvm/gems/ruby-1.8.7-p302@tobiska/gems/rake-0.9.2.2/lib/rake/rdoctask.rb

I tried to read this tip http://matthew.mceachen.us/blog/howto-fix-rake-rdoctask-is-deprecated-use-rdoc-task-instead-1169.html but my Rakefile is OK.

I have no idea, how to solve this problem. Any tips? Thanks a lot.

Martin

回答1:

You can have multiple versions of rake on your system and you can view them by running

$ gem list
=> rake

(0.9.2.2, 0.9.2, 0.8.7) To define a version in my project, define it in the Gemfile as

gem 'rake', '0.8.7'

then run

bundle update rake

Your project version is now as specified in the Gemfile and your WARNING is now gone.



回答2:

In addition to change Gemfile and run 'bundle update rake' need run for me too:

gem uninstall rake -v 0.9.2.2
gem uninstall rake -v 0.9.2
gem install rake -v 0.8.7


回答3:

In some projects that don't invoke the entire rails stack, adding rdoc to the Gemfile was the key to success for me:

group :development, :test do
  gem 'rake', '~> 0.9.2.2'
  gem "rdoc", '~> 3.12'
end

UPDATE: This was still bugging me with a rails 3.0.x project. Rakefile, gems all seemed ok but I was still getting the issue. To find out exactly where the warning wacoming from I put a canary in gems/rake-0.9.2.2/lib/rake/rdoctask.rb:

if Rake.application
  begin
    raise 'where am i'                                                                
  rescue                                                                       
    puts $@                                                                    
  end 
  Rake.application.deprecate('require \'rake/rdoctask\'', 'require \'rdoc/task\' (in RDoc 2.4.2+)', __FILE__)
end

This immediately pointed to the issue in the rails stack itself. A quick check and it is apparent that rails 3.0.8 is full of requires to rake/rdoctask. Updating to rails (3.0.9 or higher I believe) fixes the issue (or you can downgrade rake as others have suggested).

But while you are stuck on ~ 3.0.8 and don't want to downgrade rake, you can suppress the warning by setting ignore_deprecate in your Rakefile:

require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'rake/testtask'
require 'rdoc/task'

# add this (and perhaps make it conditional on Rails.version if you like):
Rake.application.options.ignore_deprecate = true

Babylon::Application.load_tasks

Why suppress the warning? My main motivation was to ensure cron jobs that invoke rake don't log and email spurious output.