开发者

How do I create a global rakefile on Windows 7?

I want to be able to create a rakefile on Windows 7 that I can call with the rake -g <taskname> or rake --system <taskname> command. Where do I save the rakefile? I've tried creating a Rake directory under my user directory (c:\users\me\rake), but when I call rake -g hello_world, rake errors out saying it doesn't know how to build the :hello_world task, which makes me think it just can't see the rakefile. Here's what my global rakefile looks like:

require 'rake'

desc "a hello world task"    
task :hello_world do 开发者_如何学JAVA   
  puts "hello from your global rakefile"    
end


Figured it out - turns out Rake expects global rakefiles to end in a ".rake" extension. I changed the example above to this:

require 'rake'

desc "a hello world task"    
task :hello_world do    
  puts "hello from {__FILE__}"    
end

And saved it as "testing.rake" in my c:\users\me\rake\ directory. I opened up a command prompt to a random directory and ran "rake -g hello_world" and got this output:

C:\Windows\system32>rake -g hello_world
(in C:/Windows/system32)
hello from C:/Users/me/Rake/testing.rake


Rake looks for Rakefile in the current directory unless specified explicitly as in:

rake --rakefile C:\users\me\rake\[rakefile]


Rake on Windows looks for $HOME/Rake/*.rake if the target cannot be found locally. If HOME is not set, then it will use c:\Users\me\Rake as the other responders have indicated.

But, if you happen to have HOME set (as I do, operating in a mixed Cygwin/Windows 7 world), now you know where rake will be expecting to find your global rake files.

Btw, I don't find it necessary to pass the -g flag; Rake seems happy to find the global definitions on its own. I think the only case in which -g is warranted is if you need to be absolutely sure there is no rake task of the same name locally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜