Maven
vim ~/.m2/settings.xml
<settings>
...
<proxies>
<proxy>
<id>my-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>xxx.xxx.xxx.xxx</host>
<port>xxx</port>
<username>xxx</username>
<password>xxx</password>
<nonProxyHosts>xxx</nonProxyHosts>
</proxy>
...
</proxies>
...
</settings>
proxies下可以有多个 proxy 元素,如果声明了多个 proxy 元素,则默认情况下第一个被激活的 proxy 会生效
active 的值为 true 表示激活该代理
protocol 表示使用的代理协议
host 主机名
port 端口号
当代理服务需要验证时,需要配置username、password、nonProxyHosts
nonProxyHost元素指定那些主机名不需要代理,可以使用|符号来分隔多个主机名。该配置也支持通配符,如*.google.com表示所有以goole.com结尾的域名访问都不需要通过代理。
Maven Wrapper
在项目文件夹中创建一个新文件.mvn/jvm.config并相应地设置属性:
-Dhttp.proxyHost=host
-Dhttp.proxyPort=port
-Dhttps.proxyHost=host
-Dhttps.proxyPort=port
-Dhttp.proxyUser=username
-Dhttp.proxyPassword=password