I have a SBT build where the tests create temporary files into a directory called temp. How can I tell SBT to delete this folder when I call the clean task?
Mark Harrah's answer is now outdated.
Here is a version that works for sbt 0.13 and upwards, and is the only of the two versions that works in sbt 1.0 and onwards.
Before sbt 0.13, you had the <+=
syntax for adding additional values, and you could apply
on keys.
With 0.13, a new, more uniform syntax was introduced, in part called value
DSL. As of 1.0, the old syntax has been removed.
// From the old, apply-based version...
cleanFiles <+= baseDirectory { base => base / "temp" }
// ...we change to .value and collection-like syntax
cleanFiles += baseDirectory.value / "temp"
cleanFiles
and other collection-based keys now mimic a (mutable) collection, so you can append values to it via a +=
operator. If you have multiple values, use ++=
with a List
or Seq
instead.
.value
does not force the evaluation of baseDirectory
when you write it, but each time cleanFiles
is calculated, so it's different for each sub-project.
There is also a slight difference in the inspect clean-files
syntax.
hyphen-named-commands
have been deprecated in 0.13 and removed in 1.0. They were replaced with lowerCamelCaseCommands
, so it's the same in the console as in your build.sbt
.inspect
doesn't show the value of your key anymore (I could not find a version information for that). Instead, you have to use show
.
sbt:root-_t> show cleanFiles
[info] * C:\Users\Adowrath\_T\target\scala-2.12
[info] * C:\Users\Adowrath\_T\target\streams
[info] * C:\Users\Adowrath\_T\temp
[success] Total time: 0 s, completed 06.02.2018, 10:28:00
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With