# Chaining together Rakefiles

**URL:** <https://www.ruby-forum.com/t/chaining-together-rakefiles/103133>\
**Category:** Rails\
**Created:** [May 2, 2007, 6:30am UTC](https://www.ruby-forum.com/t/chaining-together-rakefiles/103133 "2007-05-02T06:30:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jjantz](https://www.ruby-forum.com/u/jjantz)\
**Post date:** [May 2, 2007, 6:30am UTC](https://www.ruby-forum.com/t/chaining-together-rakefiles/103133/1 "2007-05-02T06:30:31Z")

</div>

Hello.

Can someone explain the best way to chain together Rakefiles?

I am working on a project with the following layout:

# comon libraries

depot/common

# one rails appserver

depot/projectA

# another rails appserver

depot/projectB

All of these projects (common, projectA, projectB) have their own  
Rakefiles that allow the standard test targets (e.g. test,  
test:units). I would like to have a Rakefile in the depot directory  
be able to call into one or more of the projects’ Rakefiles. For  
example, running “rake test” in depot would be able to run “rake test”  
in one or more of the subprojects. I’d also like to do something  
similar for code coverage tasks.

What is the best way to do this? Executing the projects’ Rakefiles  
from the master Rakefile via something like this doesn’t work since  
“rake test” needs to be run from the project’s base directory:

ruby(“projectA/Rakefile test”)

And even if that did work, it seems like there would be a cleaner way.

I appreciate any thoughts.

Jeff

---

<div class="post-metadata">

**Author:** ![jjantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jjantz](https://www.ruby-forum.com/u/jjantz)\
**Post date:** [May 2, 2007, 4:25pm UTC](https://www.ruby-forum.com/t/chaining-together-rakefiles/103133/2 "2007-05-02T16:25:29Z")

</div>

On 5/1/07, Jeff J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> And even if that did work, it seems like there would be a cleaner way.

def rake(\*args)  
ruby “-S”, “rake”, \*args  
end

namespace :projectA do  
task :test do  
Dir.chdir(“projectA”) { rake “test” }  
end  
end

* * *

rake projectA:test

Cheers,  
/Nick

---

<div class="post-metadata">

**Author:** ![jjantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jjantz](https://www.ruby-forum.com/u/jjantz)\
**Post date:** [May 2, 2007, 7:43pm UTC](https://www.ruby-forum.com/t/chaining-together-rakefiles/103133/3 "2007-05-02T19:43:57Z")

</div>

That works great. Thanks.

Jeff
