[Rake-devel] Task for nested instance of Rake

Jesper Tholstrup Pedersen (JUP) JUP at ramboll.com
Wed Feb 23 06:59:53 EST 2011

> I would try:
> namespace "SubProject1"
>   load "./SubProject1/Rakefile.rb"
> end

That worked perfectly...

Changing the import statement to load solved the first part of my

The second part is making the loaded rakefile run from the correct sub
At the moment I have encapsulated this in a task.

If you have any suggestions as to how the this could be packaged as a
new task flavor, I'm all ears.

My solution so far looks like this:
-- Master-rakefile --

require "rake"

task :default => [:master_build]

task :master_build => [:build_dependencies] do
  puts "task :master_build run."

task :build_dependencies => [:build_sub1] do
  puts "task :build_dependencies run."

@sub1_directory = Dir.pwd + "/Sub1"
namespace "sub1" do
  puts "Importing sub1."
  load "#{@sub1_directory}/Rakefile.rb"
  puts "sub1 imported."

task :build_sub1 do
  current_directory = Dir.pwd
  Dir.chdir "#{@sub1_directory}"
  Dir.chdir "#{current_directory}"

-- sub-rakefile --

require "rake"

task :default => [:build]

task :build do
  puts "task :build run."
  puts "Current directory: #{Dir.pwd}"

>> Now initially what goes wrong is that the task :default contains 2 
>> prerequisites after the Sub1\Rakefile.rb is loaded. The result is
>> invoking the :default task of the master also invokes the :default 
>> task of the sub.

> I would expect this to happen, as the sub project is usually a part of
the master project.

Yes, that does require some explanation: 
The short answer is that a sub-project at times are part of more than
one master project.

The long answer is that in the interest of continues integration I want
dependent libraries and frameworks built and tested every time a release
is underway. This is why it is so important that the sub-projects are
independent of the master, they must be able to be a sub-project in
several projects. In essence the sub-project is not owned by the master
project in this setting.

By the way, thank you for your help so far.


More information about the Rake-devel mailing list