简体   繁体   中英

Is it possible to use in a Rakefile tasks from another one?

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?

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM