在pom.xml中设置Maven代理不在settings.xml中

问题描述

我需要为Maven设置HTTP代理来访问存储库。 但是,由于给定的环境,我无法在Maven settings.xml文件中设置代理。

所以我想知道是否可以在项目pom.xml文件(或项目或mvn命令中的其他任何位置)中设置代理。

这可能吗?如果可以,怎么办?谢谢!

解决方法

好的,我明白了

一个人可以使用 custom settings.xml mvn -s settings.xml ...来调用Maven,并使用这样的自定义settings.xml(例如pom.xml旁)。代理的以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<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">
  <proxies>
   <proxy>
      <id>proxy_http</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.example.com</host>
      <port>8080</port>
      <nonProxyHosts>example.com</nonProxyHosts>
    </proxy>
   <proxy>
      <id>proxy_https</id>
      <active>true</active>
      <protocol>https</protocol>
      <host>proxy.example.com</host>
      <port>8080</port>
      <nonProxyHosts>example.com</nonProxyHosts>
    </proxy>
  </proxies>
</settings>

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...