How do I make a Rake Task run after all other tasks? (i.e. a Rake AfterBuild task)

前端 未结 7 980
感动是毒
感动是毒 2021-02-02 12:39

I\'m new to Rake and using it to build .net projects. What I\'m interested in is having a Summary task that prints out a summary of what has been done. I want this task to alw

7条回答
  •  北恋
    北恋 (楼主)
    2021-02-02 13:22

    You should be able to do this with 'enhance':

    Rake::Task["my_task"].enhance do
      Rake::Task["my_after_task"].invoke
    end
    

    This will cause 'my_after_task' to be invoked after 'my_task'.

    If you want to apply this to all tasks, just loop over all the tasks and call enhance for each:

    Rake::Task.tasks.each do |t| 
      t.enhance do 
        Rake::Task["my_after_task"].invoke
      end
    end
    

    Full test file:

    task :test1 do 
      puts 'test1'
    end
    
    task :test2 do 
      puts 'test2'
    end
    
    Rake::Task.tasks.each do |t|
      t.enhance do 
        puts 'after'
      end
    end
    

    And the output:

    $ rake test1
    test1
    after
    
    $ rake test2
    test2
    after
    

提交回复
热议问题