scala 摆脱SBT生成的*一切*的简单方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4483230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 02:40:22  来源:igfitidea点击:

An easy way to get rid of *everything* generated by SBT?

scalasbt

提问by Wilfred Springer

Is there an easy way to get rid of everything getting generated as a result of performing an SBT build? It turns out it creates target directories all over the place. Performing

有没有一种简单的方法可以摆脱由于执行 SBT 构建而生成的所有内容?事实证明,它会在所有地方创建目标目录。表演

sbt clean clean-cache clean-lib clean-plugins

... doesn't get rid of all.

......并没有摆脱所有。

回答by RudeDude

On my system (Ubuntu Linux) with SBT 0.13.5 and some projects from the Coursera Functional Programming course I found the folders all totalled up to 2.1GB for 12 projects due to all the cache files and duplicated Scala downloads.

在使用 SBT 0.13.5 的系统 (Ubuntu Linux) 和 Coursera 函数式编程课程中的一些项目上,由于所有缓存文件和重复的 Scala 下载,我发现 12 个项目的文件夹总计高达 2.1GB。

The current SBT commands that work and get almosteverything cleaned is:

当前有效并清除几乎所有内容的SBT 命令是:

sbt clean clean-files

This removes the top level "target" and "lib_managed" folders (23MB down to 3.2MB in this case) but leaves some target folders under project:

这将删除顶级“目标”和“lib_managed”文件夹(在本例中为 23MB 到 3.2MB),但在项目下保留了一些目标文件夹:

./project/project/project/target
./project/project/target
./project/target

This is where the Linux find command (also posted by @Hyman-oconnor) is very helpful:

这是 Linux find 命令(也由 @Hyman-oconnor 发布)非常有用的地方:

find . -name target -type d -exec rm -rf {} \;

This gets us back down to a mere 444KB for one of my own projects and the 2.1GB goes down to 5.0MB !

对于我自己的一个项目,这让我们回到了仅仅 444KB,而 2.1GB 又降到了 5.0MB!

In windows you won't have as many useful command line options, e.g. no star wildcards in path names, but you can always try and force it with:

在 Windows 中,您将没有那么多有用的命令行选项,例如路径名中没有星号通配符,但您始终可以尝试强制使用:

rmdir /s /q target project/target project/project/target

The best I can do on automatically finding is a DIR command:

我能做的最好的自动查找是一个 DIR 命令:

dir /ad /s /b | find "target"

回答by Robin Green

Obviously this is very important for reproducible builds on an integration server such as Jenkins!

显然,这对于 Jenkins 等集成服务器上的可重现构建非常重要!

Ensure that all files, including the ivy cache, are stored within the integration server workspace, by supplying command line arguments such as this to sbt:

通过向 sbt 提供如下命令行参数,确保所有文件(包括 ivy 缓存)都存储在集成服务器工作区中:

-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy

and then click the Wipe Out Workspace button in Jenkins, or the equivalent in other integration servers. That should definitely do it!

然后单击 Jenkins 中的 Wipe Out Workspace 按钮,或其他集成服务器中的等效按钮。那绝对应该这样做!

Or if you are using a recent version of the sbt launcher script, you can simply add -no-shareinstead.

或者,如果您使用的是最新版本的 sbt 启动程序脚本,则只需添加即可-no-share

回答by Adrian Hempel

On Linux or similar, this is better than find -name, as it won't accidentally remove any directory named targetthat might exist in your source code:

在 Linux 或类似版本上,这比 好find -name,因为它不会意外删除target源代码中可能存在的任何命名目录:

find . -regextype posix-awk -regex \.(/project)*/target -exec rm -r {} +

If you're running this command within a shell, you'll need to quote the regular expression, for example, for bash:

如果您在 shell 中运行此命令,则需要引用正则表达式,例如,对于 bash:

find . -regextype posix-awk -regex '\.(/project)*/target' -exec rm -r {} +

With BSD find (e.g. on Mac OS X) the command will be:

使用 BSD find(例如在 Mac OS X 上)命令将是:

find -E . -regex \.(/project)*/target -exec rm -r {} +

回答by Jose Miguel

I agree with the very good suggested solutions, personally I include a slight variation as a gnu make task.

我同意非常好的建议解决方案,我个人在 gnu make 任务中包含了一些细微的变化。

content of Makefile:

Makefile的内容:

clean:
    find . -name target | xargs rm -fr

and then run:

然后运行:

make clean

I like using Makefiles as code as documentation.

我喜欢使用 Makefile 作为代码作为文档。