Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using rake import (calling other rakefiles)

Here's my primary rake file

subrake = 'subrake'

task :init => [subrake] do
  #call subrake.build
end

import subrake

I see documentation on how the above steps work, but I can't figure out how to call tasks in the other subrake file. BTW, those tasks may have the same name as mine, is this an issue?

like image 247
Drew Avatar asked Dec 22 '10 03:12

Drew


1 Answers

I guess I'm late with my answer, but I had the same question just few moments ago. So the solution might be useful for someone.

Rakefile.rb

subrake = 'subrake'

task :default => :init

task :init => ["#{subrake}:init"] do
  Rake::Task["#{subrake}:build"].invoke
end

require "#{Dir.pwd}/#{subrake}"

subrake.rb

namespace :subrake do

  desc "Init"
  task :init do
    puts 'Init called'
  end

  desc "Build"
  task :build do
    puts 'Build called'
  end

end

I guess the code describes itself just good, but I want to stop on one moment. When you are calling require, you should provide for a subrake file a full path (like in my sample) or '.\subrake' (if it is in a working directory)

like image 130
ie. Avatar answered Nov 15 '22 01:11

ie.