在哪里指定maven存储库,pom.xml或settings.xml的最佳位置? [英] Where is the best place to specify maven repositories, pom.xml or settings.xml?

查看:222
本文介绍了在哪里指定maven存储库,pom.xml或settings.xml的最佳位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里指定为maven项目pom.xmlsettings.xml所需的存储库的最佳位置?每个位置的优缺点是什么?什么是最佳做法?

Where is the best place to specify required repositories for maven projects, pom.xml or settings.xml? What are the pros and cons of each location? What is best practice?

在我看来,由于许多原因,在POM中定义存储库会更好:

It seems to me that defining the repositories in the POM is better for a number of reasons:

  • 可再现性:相关工件来自POM中显式声明的已知位置.用户的配置错误的存储库引起问题的机会也更少.
  • 可移植性:此POM将在安装了maven的任何人的计算机上构建.对其他用户配置的存储库设置没有其他要求.
  • 易用性:新开发人员更容易检索和构建项目,因为需要进行的配置较少.

可能的一个缺点是,如果将来存储库的位置发生变化,则需要安装代理或需要发布旧软件的修补程序版本以指定新的存储库位置(或.m2/settings.xml始终可以提供其他存储库,例如不得已).但是,这似乎是发行管理中良好的可重复性和可移植性的必要分支,而不是不利条件.

Perhaps a con is that if the location of the repository changes in the future, proxies need to be installed or patch releases of old software need to be released specifying the new repository locations (or .m2/settings.xml can always provide additional repositories as a last resort). However, this seems like a necessary ramification of good reproducibility and portability in release management rather than a con.

还有其他想法吗?

推荐答案

在哪里为maven项目,pom.xml或settings.xml指定所需的存储库?每个位置的优缺点是什么?什么是最佳做法?

Where is the best place to specify required repositories for maven projects, pom.xml or settings.xml? What are the pros and cons of each location? What is best practice?

我将在项目pom.xml中亲自定义特定项目所需的存储库,因为它使构建易于移植.仅在我看来,settings.xml文件应仅用于用户特定的内容或机密内容.确实没有,要求用户添加存储库位置(即使已正确记录),以某种方式破坏了maven的功能之一(透明依赖项处理),我不喜欢这个想法.

I'd personally define the repositories required by a particular project in the project pom.xml because it keeps the build portable. The settings.xml file should be used for user specific or secret things only in my opinion. No really, asking the user to add repository locations, even if this is properly documented, somehow defeats one of maven's feature (transparent dependency handling) and I don't like this idea.

对于使用settings.xml处理存储库,我可以想到的唯一好"用例是当您拥有公司存储库并希望Maven使用此存储库而不是公共存储库时.例如,为避免连接到任何公共存储库,您可以将公司存储库声明为所有公共存储库的镜像:

The only "good" use case I can think of for using settings.xml to deal with repositories is when you have a corporate repository and want Maven to use this repository instead of public ones. For example, to avoid connections to any public repository, you would declare the corporate repository as a mirror of all of them:

<settings>
  ...
  <mirrors>
    <mirror>
      <id>proxy-of-entire-earth</id>
      <mirrorOf>*</mirrorOf>
      <name>Maven Repository Manager running on repo.mycompany.com</name>
      <url>http://repo.mycompany.com/proxy</url>
    </mirror>
  </mirrors>
  ...
</settings>

这篇关于在哪里指定maven存储库,pom.xml或settings.xml的最佳位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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