我想分享一下我通过代理使用maven的经验。
您很可能会遇到异常和消息,例如:
repository metadata for: 'org.apache.maven.plugins' could not be retrieved from repository: central due to an error: Error transferring file: Connection refused: connect
或
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-clean- plugin:2.5: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5
如何配置Maven使用代理服务器?
最佳答案
有关为 Maven 设置代理的详细信息,请参阅 mini guide .
本质上,您需要确保全局设置 ([maven install]/conf/settings.xml
) 或用户设置 (${user.home}/.m2/settings.xml
)配置正确。最好在您的用户设置中执行此操作,以避免将密码以纯文本形式存储在公共(public)位置。
Maven 2.1 引入 password encryption ,但我还没有抽出时间来检查加密是否适用于代理设置以及存储库密码(不明白为什么它不会)。
有关信息,您的 settings.xml 中有一个注释掉的代理配置以及有关如何修改它的说明。
根据迷你指南,您的设置应如下所示:
<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>
<active>true</active>
<protocol>http</protocol>
<host>proxy.somewhere.com</host>
<port>8080</port>
<username>proxyuser</username>
<password>somepassword</password>
<nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
</proxy>
</proxies>
[...]
</settings>
关于maven - 如何通过代理使用 Maven?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1251192/