简体   繁体   English

是否可以在另一个Rakefile任务中使用?

[英]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. 我有一些Rake任务,我想在我的Rakefiles中使用。 Is it possible to include tasks defined in one rakefile from another rakefile? 是否可以在另一个rakefile中包含一个rakefile中定义的任务?

Rake files are nothing different than ruby files. Rake文件与ruby文件没什么不同。 So just load the file A containing the other tasks in your file B and they will be available when B is executed. 因此,只需加载包含文件B中其他任务的文件A,它们将在执行B时可用。

For instance, if you put the following code in your Rakefile 例如,如果您将以下代码放在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 . 然后你可以在tasks子文件夹中创建尽可能多的.rake文件,并从主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. 也许有点简陋,但它确实起了作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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