Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

scala - Add additional directory to clean task in SBT build

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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(<project>/lib_managed, <project>/target, <project>/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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...