Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add additional directory to clean task in SBT build

Tags:

scala

sbt

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?

like image 853
Felix Avatar asked May 06 '12 15:05

Felix


1 Answers

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.

Updated key appending syntax.

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.

Updated inspect and command syntax

There is also a slight difference in the inspect clean-files syntax.

  1. 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.
  2. 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
    
like image 91
Adowrath Avatar answered Sep 19 '22 17:09

Adowrath