关于ERROR: ‘rake/rdoctask’ is obsolete and no longer supported. Use ‘rdoc/task’ (available in RDoc

  • Post author:
  • Post category:其他


先理解一下rake:

Rake(http://rake.rubyforge.org)是一门构建语言,和make(www.gnu.org/software/make/)

ant(http://ant.apache.org)很想象。Rake是用Ruby写的,它支持它自己的DSL用来处理和维护

Ruby应用程序。Rails用rake的扩展来完成多种不同的任务。下面的一些在Rails用的最多的Rake任务。

正在学习《agile web development with rails》

之前在我的环境中运行了rails3.2版本下的程序,然后回到rails 3.0版本下的代码尝试运行

bundle install后 执行rake命令数据库迁移,得到如下错误

ERROR: ‘rake/rdoctask’ is obsolete and no longer supported. Use ‘rdoc/task’ (available in RDoc 2.4.2+) instead.

/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/rdoctask.rb:1:in `<top (required)>’

/home/www/.gem/ruby/1.9.1/gems/railties-3.0.5/lib/rails/tasks/documentation.rake:1:in `require’

/home/www/.gem/ruby/1.9.1/gems/railties-3.0.5/lib/rails/tasks/documentation.rake:1:in `<top (required)>’

/home/www/.gem/ruby/1.9.1/gems/railties-3.0.5/lib/rails/tasks.rb:15:in `load’

/home/www/.gem/ruby/1.9.1/gems/railties-3.0.5/lib/rails/tasks.rb:15:in `block in <top (required)>’

/home/www/.gem/ruby/1.9.1/gems/railties-3.0.5/lib/rails/tasks.rb:6:in `each’

/home/www/.gem/ruby/1.9.1/gems/railties-3.0.5/lib/rails/tasks.rb:6:in `<top (required)>’

/home/www/.gem/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:213:in `require’

/home/www/.gem/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:213:in `initialize_tasks’

/home/www/.gem/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:139:in `load_tasks’

/home/www/.gem/ruby/1.9.1/gems/railties-3.0.5/lib/rails/application.rb:77:in `method_missing’

/home/www/code/rails30/depot_r/Rakefile:7:in `<top (required)>’

/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `load’

/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `load_rakefile’

/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:589:in `raw_load_rakefile’

/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:89:in `block in load_rakefile’

/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling’

/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:88:in `load_rakefile’

/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:72:in `block in run’

/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling’

/home/www/.gem/ruby/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run’

这里说 rake/rdoctask 已经被废弃,用rdoc/task代替,用的是新版本的rake,这里的rodc/task指的是什么,没有理解,为什么新版本的rake会提示引用的库已经废弃,goole了解决方案,改写Gemfile.lock文件,将使用的rake降级为0.8.7,然后执行rake 有出现如下错误:

You have already activated rake 10.0.3, but your Gemfile requires rake 0.8.7. Using bundle exec may solve this.

/home/www/code/rails30/depot_r/config/boot.rb:22:in `<top (required)>’

/home/www/code/rails30/depot_r/config/application.rb:17:in `<top (required)>’

/home/www/code/rails30/depot_r/Rakefile:4:in `<top (required)>’

在外国的论坛上找到了解决问题的方法:

The problem is that when you have multiple versions of the same gem installed, the binary you will execute

rake

is always the latest version. If your application then depends on an older version of that gem, it can’t activate it, since the newer version is already loaded.

There are three solutions:

  1. use

    bundle exec rake

    this will always use the version from your Gemfile
  2. use bundler binstubs:

    bundle --binstubs

    . This creates a

    ./bin

    folder in your project. You can now access the binaries for the specified gem versions from your Gemfile. You can call rake with

    ./bin/rake
  3. uninstall the newer version so that the binary points to the one in your Gemfile

我用了 bundle  exec rake db:migrate 执行了 数据库迁移 执行成功



版权声明:本文为wanghaoming100原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。