有没有简单的方法可以摆脱 SBT 生成的*所有内容*?

发布于 2024-10-08 11:53:47 字数 148 浏览 8 评论 0原文

有没有一种简单的方法可以消除执行 SBT 构建时生成的所有内容?事实证明它在各处创建了目标目录。表演

sbt clean clean-cache clean-lib clean-plugins

……并不能摆脱一切。

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 clean clean-cache clean-lib clean-plugins

... doesn't get rid of all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

洛阳烟雨空心柳 2024-10-15 11:53:47

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

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

sbt clean clean-files

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

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

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

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

这使我自己的项目之一的大小回落到仅仅 444KB,而 2.1GB 下降到 5.0MB!

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

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

在自动查找方面我能做的最好的事情是 DIR 命令:

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

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.

The current SBT commands that work and get almost everything cleaned is:

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:

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

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

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 !

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:

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

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

dir /ad /s /b | find "target"
以往的大感动 2024-10-15 11:53:47

显然,这对于在 Jenkins 等集成服务器上进行可重复构建非常重要!

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

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

然后单击 Jenkins 中的“擦除工作区”按钮或等效按钮在其他集成服务器中。那绝对应该做到!

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

Obviously this is very important for reproducible builds on an integration server such as 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:

-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!

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

紫罗兰の梦幻 2024-10-15 11:53:47

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

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

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

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

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

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

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

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:

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

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

find -E . -regex \.(/project)*/target -exec rm -r {} +
云醉月微眠 2024-10-15 11:53:47

我同意非常好的建议解决方案,就我个人而言,我将一个细微的变化作为 gnu make 任务。

Makefile 的内容:

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

然后运行:

make clean

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

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

content of Makefile:

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

and then run:

make clean

I like using Makefiles as code as documentation.

筱武穆 2024-10-15 11:53:47

您可以使用 Pretty Clean 清理所有开发工具缓存,包括 SBT。

PrettyClean 还会清理 SBT 项目的目标文件夹。

You can use Pretty Clean to clean the all of dev tools caches including SBT.

PrettyClean also cleans the SBT project's target folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文