I have some Rake tasks I'd like to use in my Rakefiles. Is it possible to include tasks defined in one rakefile from another rakefile?
+3
A:
Rake files are nothing different than ruby files. So just load the file A containing the other tasks in your file B and they will be available when B is executed.
For instance, if you put the following code in your Rakefile
Dir['tasks/*.rake'].each { |file| load(file) }
then you can create as many .rake
files in the tasks
subfolder and call them from the main Rakefile
.
Simone Carletti
2010-02-26 16:46:55
Yup. I always do this, to a) keep to one domain per file (all gem related tasks in `gem.rake`, all test related tasks in `test.rake`, all documentation related tasks in `doc.rake`) and b) share common tasks between different projects (calling RDoc, RSpec, RubyGems is really the same, independent of the specific project).
Jörg W Mittag
2010-02-26 16:57:19
+1
A:
I've just done something similar with the following:
task :master do
`rake slave`
end
task :slave do
puts "Hello World"
end
Perhaps a little rudimentary, but it does the job.
kez
2010-03-09 10:44:41