Search code examples
rubyrakerake-task

Is there a way to run a rake task without running the prerequisites?


Is there a command line switch I'm missing?

At the moment I'm having to do this:

#task :install => :build do
task :install do
end

Solution

  • I seem to have solved this problem by simply adding extra tasks in the format "taskname_no_prerequisites". So for example in the code below executing "rake install_no_prerequisites" would not cause "build" to be executed.

    desc "Build"
    task :build do
      puts "BUILDING..."
    end
    
    desc "Install"
    task :install => :build do
      puts "INSTALLING..."
    end
    
    Rake::Task::tasks.each do |task|
      desc "#{task} without prerequisites"
      task "#{task}_no_prerequisites".to_sym do
        task.invoke_without_prerequisites
      end
    end
    
    module Rake
      class Task
        def invoke_without_prerequisites
          execute
        end  
      end
    end