How do I find the source file for a rake task?

I know this is an old question, but in any case:

rake -W

This was introduced in rake 0.9.0.

http://rake.rubyforge.org/doc/release_notes/rake-0_9_0_rdoc.html

Support for the –where (-W) flag for showing where a task is defined.


Despite what others have said, you can programmatically get the source location of rake tasks in a rails application. To do this, just run something like the following in your code or from a console:

# load all the tasks associated with the rails app
Rails.application.load_tasks

# get the source locations of actions called by a task
task_name = 'db:schema:load' # fully scoped task name
Rake.application[task_name].actions.map(&:source_location)

This will return the source locations of any code that gets executed for this task. You can also use #prerequisites instead of #source_location to get a list of prerequisite task names (e.g. 'environment', etc).

You can also list all tasks loaded using:

Rake.application.tasks

UPDATE: See Magne's good answer below. For versions of rake >= 0.9.0 you can use rake -W to show the source location of your rake tasks.