在 VCS 中存储 .jar 文件的最佳实践(SVN、Git 等) [英] Best practice to store .jar files in VCS (SVN, Git, ...)

查看:28
本文介绍了在 VCS 中存储 .jar 文件的最佳实践(SVN、Git 等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,在 Maven 时代,不建议将库存储在 VCS 中,但有时它是有道理的.

我的问题是如何最好地存储它们 - 压缩还是未压缩?未压缩的它们更大,但如果用更新的文件替换它们几次,那么两个未压缩的 .jar 文件之间的存储差异可能比压缩文件的差异小得多.有人做过测试吗?

解决方案

在 VCS(SVN、Git 等)中存储 .jar 文件的最佳实践:不要.

这在像 SVN 这样的 CVCS(集中式 VCS)中是有意义的,它可以处理数百万个文件,无论它们的大小如何.

它不在 DVCS 中,尤其是像 Git(和 它的限制):

  • 二进制文件不适合 VCS.
  • 默认情况下,克隆 DVCS 存储库将为您提供所有其历史记录,以及所有 jar 版本.
    无论这些 jar 压缩得多么好,这都会很慢并占用大量磁盘空间.
    您可以尝试使用浅克隆,但这是高度不切实际.

使用第二个存储库,例如 Nexus,用于存储这些 jar,以及仅引用 txt 文件(或 Maven 项目)以获取正确的 jar 版本.
工件仓库更适合 分发和发布管理目的.

<小时>

综上所述,如果您必须将 jar 存储在 Git 存储库中,我会建议最初以压缩格式存储它们(这是 jar 的默认格式:请参阅 创建 JAR 文件)
压缩和未压缩格式都会被 Git 视为二进制文件,但至少,在压缩格式中,克隆和检出所需的时间更少.

然而,许多线程提到了以未压缩格式存储 jar 的可能性::><块引用>

我正在使用一些存储库,这些存储库将常规的 50MB tarball 签入其中.
我说服他们不要压缩 tarball,并且 git 在它们之间进行增量压缩方面做得相当不错(尽管这样做需要相当多的 RAM).

您有更多关于 Git 上的已删除对象的更多信息::><块引用>

  • 处理二进制或文本没有区别;
  • delta 不一定与之前版本中的路径相同,因此即使添加到历史记录中的新文件也可以以 delitified 形式存储;
  • 当使用存储在 deltified 表示中的对象时,与在压缩的基本表示中使用相同的对象相比,它会产生更多的成本.Deltification 机制会在考虑此成本和空间效率的情况下进行权衡.

因此,如果克隆和检出不是您必须每 5 分钟执行一次的常见操作,那么在 Git 中以未压缩格式存储 jar 会更有意义,因为:

  • Git 会压缩/计算这些文件的增量
  • 您的工作目录中最终会出现未压缩的 jar,这些 jar 可能会被更快地加载.

建议:未压缩.

I know, in the time of Maven it is not recommended to store libraries in VCS, but sometimes it makes sense, though.

My question is how to best store them - compressed or uncompressed? Uncompressed they are larger, but if they are replaced a couple of times with newer ones, then maybe the stored difference between two uncompressed .jar files might be much smaller than the difference of compressed ones. Did someone make some tests?

解决方案

Best practice to store .jar files in VCS (SVN, Git, …): don't.

It could make sense in a CVCS (Centralized VCS) like SVN, which can handle millions of files whatever their size is.

It doesn't in a DVCS, especially one like Git (and its limits):

  • Binary files don't fit well with VCS.
  • By default, cloning a DVCS repo will get you all of its history, with all the jar versions.
    That will be slow and take a lot of disk space, not matter how well those jar are compressed.
    You could try to play with shallow cloning, but that's highly unpractical.

Use a second repository, like Nexus, for storing those jars, and only reference a txt file (or a pom.xml file for Maven project) in order to fetch the right jar versions.
A artifact repo is more adapted for distribution and release management purpose.


All that being said, if you must store jar in a Git repo, I would have recommend initially to store them in their compressed format (which is the default format for a jar: see Creating a JAR File)
Both compressed and uncompressed format would be treated as binary by Git, but at least, in a compressed format, clone and checkout would take less time.

However, many threads mentions the possibility to store jar in uncompressed format:

I'm using some repos that get regular 50MB tarballs checked into them.
I convinced them to not compress the tarballs, and git does a fairly decent job of doing delta compression between them (although it needs quite a bit of RAM to do so).

You have more on deltified object on Git here:

  • It does not make a difference if you are dealing with binary or text;
  • The delta is not necessarily against the same path in the previous revision, so even a new file added to the history can be stored in a delitified form;
  • When an object stored in the deltified representation is used, it would incur more cost than using the same object in the compressed base representation. The deltification mechanism makes a trade-off taking this cost into account, as well as the space efficiency.

So, if clones and checkouts are not common operations that you would have to perform every 5 minutes, storing jar in an uncompressed format in Git would make more sense because:

  • Git would compressed/compute delta for those files
  • You would end up with uncompressed jar in your working directory, jars which could then potentially be loaded more quickly.

Recommendation: uncompressed.

这篇关于在 VCS 中存储 .jar 文件的最佳实践(SVN、Git 等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆