我使用以下settings.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">
<localRepository>C:\Dev\m2</localRepository>
<proxies>
<proxy>
<id>1</id>
<active>true</active>
<protocol>http</protocol>
<username>user</username>
<password>pass</password>
<host>host</host>
<port>port</port>
<nonProxyHosts>127.0.0.1|localhost|maven</nonProxyHosts>
</proxy>
<proxy>
<id>1</id>
<active>true</active>
<protocol>https</protocol>
<username>user</username>
<password>pass</password>
<host>host</host>
<port>port</port>
<nonProxyHosts>127.0.0.1|localhost|maven</nonProxyHosts>
</proxy>
</proxies>
<profiles>
<profile>
<id>default</id>
<repositories>
<repository>
<id>nexus1</id>
<url>http://company-nexus.com</url>
</repository>
<repository>
<id>nexus2</id>
<url>http://company-deploy-nexus.com</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus1</id>
<url>http://company-nexus.com</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
<pluginGroups>
<pluginGroup>com.atlassian.maven.plugins</pluginGroup>
</pluginGroups>
</settings>
具有代理设置和公司nexus配置。我想要代理设置,因为在其中一个项目中我配置了maven中央存储库
<repository>
<id>maven-central</id>
<url>http://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
然而,当一个可以从公司nexus检索所有内容的项目(即不需要通过代理访问http://repo1.maven.org/maven2
尝试下载依赖项时我得到
[ERROR] Failed to execute goal on project someproject: Could not resolve dependencies for project groupId:artifactId:jar:1.0-SNAPSHOT:
Failed to collect dependencies at junit:junit:jar:4.12: Failed to read artifact descriptor for junit:junit:jar:4.12:
Could not transfer artifact junit:junit:pom:4.12 from/to central (http://company-nexus.com):
Access denied to: http://company-nexus.com/nexus/content/groups/public/junit/junit/4.12/junit-4.12.pom, ReasonPhrase: URLBlocked. -> [Help 1]
当我删除settings.xml
中的代理设置时,我获得了成功。
同样,我需要一些但不是所有项目的代理设置,因为我们的公司nexus拥有大部分回购
感谢您的帮助!
答案 0 :(得分:1)
在nonProxyHosts标记中添加本地nexus存储库主机名
<nonProxyHosts>localhost|company-deploy-nexus.com|company-nexus.com|localhost</nonProxyHosts>