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?
Use this setting in the project containing the temp directory:
cleanFiles <+= baseDirectory { base => base / "temp" }
This adds the "temp" directory to the list of files to recursively delete when clean runs.
The < means "configure in terms of other tasks/settings", the + means append to the current list of files, and baseDirectory is the setting providing the base directory of the project.
You can see how clean is configured using the inspect command, documented in more detail on the Inspecting Settings page. An edited sbt session shows usage in this case:
> inspect clean
Task: Unit
Description:
Deletes files produced by the build, such as generated sources, compiled classes, and task caches.
Dependencies:
clean-files
clean-keep-files
> inspect clean-files
Setting: scala.collection.Seq[java.io.File] = List(/lib_managed, /target, /temp)
Description:
The files to recursively delete during a clean.
Dependencies:
managed-directory
target
base-directory
You can see this shows you if it is a task or setting, the type, a description, and the tasks/settings used as inputs.