简体   繁体   English

使用公共 Maven 存储库而不是本地库的优点

[英]Advantages of using public maven repository for libraries instead of local

What are the advantages of using Maven's public repository vs storing your libraries locally?使用 Maven 的公共存储库与在本地存储库相比有哪些优势?

I see the following disadvantages in using public repository:我发现使用公共存储库有以下缺点:

  • If for some reason some library is updated my application will probably crash, considering I use hundreds of libraries that's bound to happen sometime.如果由于某种原因更新了某个库,我的应用程序可能会崩溃,考虑到我使用了数百个肯定会在某个时候发生的库。
  • If a specific library version is specified to avoid newer versions to break the application, that specific version might not be available anymore.如果指定了特定的库版本以避免更新版本破坏应用程序,则该特定版本可能不再可用。
  • The repositories might always be subject to network problems or similar error blocking development of the software completely, a local lib folder with all the required jars shared through git is more robust.存储库可能总是受到网络问题或类似错误的影响,完全阻止了软件的开发,通过 git 共享所有必需 jar 的本地 lib 文件夹更加健壮。

In order to avoid using a public repo I'm following this advice , someone however also suggested为了避免使用公共回购,我遵循了这个建议,但是有人也建议

" run something like Nexus, your own maven repo that you can upload 3rd party proprietary jar files, and also proxy other public repositories, to save on bandwith? ". 运行像 Nexus 这样的东西,你自己的 maven 存储库,你可以上传 3rd 方专有的 jar 文件,也可以代理其他公共存储库,以节省带宽? ”。

That really summarizes my doubts: why go through all that pain for simply sharing library files to a couple of developers?这确实总结了我的疑虑:为什么要为简单地将库文件共享给几个开发人员而经历所有痛苦?

  • If for some reason some library is updated my application will probably crash, considering I use hundreds of libraries that's bound to happen sometime. 如果由于某种原因某些库被更新,我的应用程序可能会崩溃,考虑到我使用了数百个必然会发生的库。

No. I know Murphy's law states that anything that can happen will happen. 不,我知道墨菲的法律规定任何可能发生的事情都会发生。 But libraries published in Maven Central are supposed to be stable. 但是在Maven Central发布的图书馆应该是稳定的。 If a library is updated, it will be with a new version so there are no conflicts. 如果库已更新,则它将使用新版本,因此不存在冲突。 No sane maintainer of a library would go against that. 没有理智的图书馆维护者会反对。

  • If a specific library version is specified to avoid newer versions to break the application, that specific version might not be available anymore. 如果指定了特定库版本以避免新版本破坏应用程序,则该特定版本可能不再可用。

No. You can't remove an artifact from Maven Central . 不可以您无法从Maven Central中删除工件 So this is not possible. 所以这是不可能的。

  • The repositories might always be subject to network problems or similar error blocking development of the software completely, a local lib folder with all the required jars shared through git is more robust. 存储库可能总是受到网络问题或完全阻止软件开发的类似错误的影响,通过git共享所有必需jar的本地lib文件夹更加健壮。

While that is true, Maven keeps a cache of all artifacts inside your local repository. 虽然这是真的,但Maven会在本地存储库中保留所有工件的缓存。 It just needs to download them once. 它只需要下载一次。


The advantage of using an internal repository manager goes beyond the scope of caching Maven Central. 使用内部存储库管理器的优势超出了缓存Maven Central的范围。 It allows a central entry point for all dependencies, whether or not those dependencies are public. 它允许所有依赖项的中央入口点,无论这些依赖项是否公开。 It can also host internal library and private libraries (like Oracle JDBC). 它还可以托管内部库和私有库(如Oracle JDBC)。 Also, using it is transparent for Maven projects: dependencies are declared exactly the same way, whether it is a public artifact or a in-house one. 此外,使用它对于Maven项目是透明的:依赖关系的声明方式完全相同,无论是公共工件还是内部工件。

Just one important advantage of using central repository: You do not need to add all transitive dependencies manually. 使用中央存储库的一个重要优势:您无需手动添加所有传递依赖项。 Usually this list can be huge and you'll be able to notice it only by running you application while auto-dependency management will update classpath with all required libs. 通常这个列表可能很大,你只能通过运行你的应用程序来注意它,而自动依赖管理将更新带有所有必需库的类路径。

Few more advantages:更多优点:

  • Leveraging CDN: maven central delivers artifacts across the world using CDN.利用 CDN:maven central 使用 CDN 在世界范围内交付工件。 This will significantly improve timings for first installs where almost all dependencies are downloaded.这将显着改善首次安装的时间,其中几乎所有依赖项都被下载。
  • Javadoc hosting: All open source artifacts hosted on maven central get free javadoc hosting on javadoc.io . Javadoc 托管:托管在 maven central 上的所有开源工件都可以在javadoc.io上获得免费的 javadoc 托管。
  • Easy discovery.轻松发现。 Maven central is well known in developer community and it is the first place where people look for dependencies and OSS distributions Maven 中心在开发者社区中是众所周知的,它是人们寻找依赖项和 OSS 发行版的第一个地方
  • Less code: Less number of repositories to configure in pom更少的代码:在 pom 中配置的存储库数量更少

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM