禁用 Maven 中央存储库 [英] Disable Maven central repository

查看:52
本文介绍了禁用 Maven 中央存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司的政策不赞成自动下载工件(它们必须得到批准),因此为了使用 Maven,我需要禁用对 Maven 中央存储库的访问.

My company's policy frowns upon artifacts downloaded automatically (they have to be approved), so in order to use Maven I need to disable access to Maven's central repository.

换句话说,我不希望 Maven 尝试从中央下载任何.

In other words, I don't want Maven to attempt any downloads from central.

我知道如何配置本地存储库(联网与否),我的想法是使用有福"的机器来更新本地存储库.

I know how to configure a local repository (networked or not), my idea is using a "blessed" machine to update the local repository.

PS:我可以在代理/网络级别阻止请求,但我问的是如何使用 Maven 的配置来做到这一点.

PS: I could block requests at the proxy/network level, but I'm asking about how to do it with Maven's configuration.

更新我终于知道怎么做了.在maven的home中,conf目录下是一个全局的settings.xml.您可以将镜像设置为 central 指向某个内部服务器,或者只是覆盖它的定义.

UPDATE I finally figured out how to do it. In maven's home, in the conf directory is a global settings.xml. You can either set a mirror to central that points to some internal server or just override it's definition.

推荐答案

同意.您的发布版本中不得直接从外部存储库下载.

Agreed. No direct downloads from external repositories should be allowed in your release builds.

你问题的具体答案是我回答的第二部分:-)

The specific answer to your question is the second part of my answer :-)

我建议设置一个本地 Maven 存储库管理器.好的选择如下:

I'd recommend setting up a local Maven repository manager. Good options are the following:

所有这些都能够充当外部可用的 Maven 中央 jar 的缓存代理.

All of these are capable of acting as a caching proxy for the externally available Maven central jars.

您可能还对 Nexus 的专业版感兴趣.它包括一个用于管理外部图书馆的采购套件.它还提供了用于集中管理 Maven 设置文件的 Maven 插件,这是我回答的第二部分...

You might also be interested in the Profession version of Nexus. It includes a Procurement suite for managing external libraries. It also provides Maven plugins for centrally managing the Maven settings file, which is the second part of my answer...

更新位于以下目录中的设置文件:

Update the settings file located in the following directory:

$HOME/.m2/settings.xml

$HOME/.m2/settings.xml

指定所有中央请求都应该重定向到本地 Maven 存储库:

Specify that all central requests should be redirected to the local Maven repository:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <mirrors>
    <mirror>
      <id>central-proxy</id>
      <name>Local proxy of central repo</name>
      <url>http://<hostname>/central</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

这篇关于禁用 Maven 中央存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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