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

前端 未结 7 1149
感动是毒
感动是毒 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:17

    Posting this as a new answer to keep the other one available. This is much less elegant as I have to get into the guts of Rake and manually update the task list, but it works.

    task :test1 do
      puts 'test1'
    end
    
    task :test2 do 
      puts 'test2'
    end
    
    task :after do
      puts 'after'
    end
    
    # top_level_tasks is't writable so we need to do this ugly
    # instance_variable_set hack...
    current_tasks =  Rake.application.top_level_tasks
    current_tasks << :after
    Rake.application.instance_variable_set(:@top_level_tasks, current_tasks)
    

    Outputs:

    $ rake test1
    test1
    after
    
    $ rake test1 test2
    test1
    test2
    after
    

提交回复
热议问题