4

I'm using a build system which defines a number of rake targets, including this one:

task :test => [:all]

This seems incorrect to me, and so I defined my own rake tasks like so:

task :test => [:spec]
task :all => [:test, :build]
task :release => [:all]
task :default => [:release]

However, now I'm getting this error when I try to build my package:

Circular dependency detected: TOP => default => all => test => all
Tasks: TOP => default => all => test
BUILD FAILED

I've come to realize that defining a rake task (or dependencies for a rake task) just appends those tasks/dependencies to the task definition! This is driving me crazy! Why can't I redefine my rake tasks as I see fit?! Is there any way to overwrite a rake task, and/or to overwrite the dependencies of a rake task?

Dasmowenator
  • 5,505
  • 5
  • 36
  • 50
  • I found this post from 2008, but it seems like such a hack! There must be a cleaner way to do this, right? http://blog.jayfields.com/2008/02/rake-task-overwriting.html – Dasmowenator May 06 '17 at 00:32

1 Answers1

5

Use this before you define your task:

Rake::Task[:test].clear

This is implemented in the rake gem, file lib/rake/task.rb You can see it also supports clear_prerequisites, clear_actions, clear_comments, clear_args as well (clear does all four things).

cliffordheath
  • 2,536
  • 15
  • 16
  • This answer truly helped me. Especially mentioning the additional methods. This is very useful to use in the `Rakefile`. – akostadinov May 10 '22 at 19:03