Rake -T 无法识别任务

问题描述 投票:0回答:1

我正在尝试设置一个 Rake 任务(没有 Rails),从而创建了一个演示 Hello World 任务。但是,运行

rake -T
rake --tasks
时不会返回任何内容,就好像任务尚未识别一样。我在这里做错了什么?

另外,当我运行

rake hello_world
时,我收到以下错误:

➜  ~/GitHub/Cerner/test git:(master) ✗ rake hello_world
rake aborted!
Don't know how to build task 'hello_world' (See the list of available tasks with `rake --tasks`)
/usr/share/rvm/gems/ruby-2.6.6/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/home/hsbagga28/gems/bin/ruby_executable_hooks:22:in `eval'
/home/hsbagga28/gems/bin/ruby_executable_hooks:22:in `<main>'
(See full trace by running task with --trace)

[更新] rakefile:

# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
$LOAD_PATH.push File.expand_path('lib', __dir__)
ruby-on-rails ruby rake
1个回答
0
投票

我最终创建了一个默认的 Rakefile:

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative "config/application"

Rails.application.load_tasks

此后

rake -T
似乎返回了我在
lib/tasks

下定义的任务
© www.soinside.com 2019 - 2024. All rights reserved.