有没有简单的方法可以摆脱 SBT 生成的*所有内容*?
有没有一种简单的方法可以消除执行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在我的系统 (Ubuntu Linux) 上,使用 SBT 0.13.5 和 Coursera 函数式编程课程中的一些项目,由于所有缓存文件和重复的 Scala 下载,我发现 12 个项目的文件夹总计高达 2.1GB。
当前有效并清理几乎所有内容的 SBT 命令是:
这将删除顶级“target”和“lib_management”文件夹(在本例中为 23MB,降至 3.2MB),但在项目下保留一些目标文件夹:
这就是 Linux find 命令(也由 @jack-oconnor 发布)非常有用的地方:
这使我自己的项目之一的大小回落到仅仅 444KB,而 2.1GB 下降到 5.0MB!
在 Windows 中,您不会有那么多有用的命令行选项,例如路径名中没有星号通配符,但您始终可以尝试使用以下命令强制它:
在自动查找方面我能做的最好的事情是 DIR 命令:
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:
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:
This is where the Linux find command (also posted by @jack-oconnor) is very helpful:
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:
The best I can do on automatically finding is a DIR command:
显然,这对于在 Jenkins 等集成服务器上进行可重复构建非常重要!
通过向 sbt 提供如下命令行参数,确保所有文件(包括 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:
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.在 Linux 或类似系统上,这比
find -name
更好,因为它不会意外删除源代码中可能存在的任何名为target
的目录:如果您在 shell 中运行此命令,您需要引用正则表达式,例如,对于 bash:
使用 BSD find(例如在 Mac OS X 上),命令将是:
On Linux or similar, this is better than
find -name
, as it won't accidentally remove any directory namedtarget
that might exist in your source code:If you're running this command within a shell, you'll need to quote the regular expression, for example, for bash:
With BSD find (e.g. on Mac OS X) the command will be:
我同意非常好的建议解决方案,就我个人而言,我将一个细微的变化作为 gnu make 任务。
Makefile 的内容:
然后运行:
我喜欢使用 Makefile 作为代码作为文档。
I agree with the very good suggested solutions, personally I include a slight variation as a gnu make task.
content of Makefile:
and then run:
I like using Makefiles as code as documentation.
您可以使用 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.