Maven没有在pom.xml中使用代理来获取远程存储库

时间:2016-01-29 10:13:07

标签: maven proxy repository pom.xml hortonworks-data-platform

我正在使用Maven构建我的代码,在我的项目pom.xml中,我已经将远程存储库配置为

 <repositories>
   <repository>
   <releases>
   <enabled>true</enabled>
   <updatePolicy>always</updatePolicy>
   <checksumPolicy>warn</checksumPolicy>
   </releases>
   <snapshots>
   <enabled>false</enabled>
   <updatePolicy>never</updatePolicy>
   <checksumPolicy>fail</checksumPolicy>
   </snapshots>
   <id>HDPReleases</id>
   <name>HDP Releases</name>
   <url>http://repo.hortonworks.com/content/repositories/releases/</url>
   <layout>default</layout>
   </repository>
   </repositories>

在Maven setting.xml中,我在代理标记下添加了详细信息,以便所有HTTPS请求在下载时都使用代理。然后,Maven无法从远程hortonworks存储库获取所需文件,并因

之类的错误而失败
[ERROR] Failed to execute goal on project flume-sources: Could not resolve dependencies for project com.hdptest:flume-sources:jar:1.0-SNAPSHOT: Failed to collect dependencies at org.apache.flume:flume-ng-core:jar:1.4.0.2.0.10.1-3: Failed to read artifact descriptor for org.apache.flume:flume-ng-core:jar:1.4.0.2.0.10.1-3: Could not transfer artifact org.apache.flume:flume-ng-core:pom:1.4.0.2.0.10.1-3 from/to hortonworks (http://repo.hortonworks.com/content/repositories/releases/): Connect to repo.hortonworks.com:80 [repo.hortonworks.com/54.225.131.199] failed: Connection timed out -> [Help 1]

我在这里可以理解什么是问题。只要Maven尝试从repo.hortonworks.com下载,它就不会使用我在settings.xml中提到的代理详细信息,因此该请求无效。但是当它向Maven传递相同的请求时

通过查看来自Maven构建的调试消息可以清楚地看到这一点,如下所示。从https://repo.maven.apache.org下载任何内容时,它会使用正确的代理详细信息。但是当从hortonworks的存储库下载任何东西时,使用代理是错误的。:

[DEBUG] =======================================================================
[DEBUG] Using transporter WagonTransporter with priority -1.0 for http://repo.hortonworks.com/content/repositories/releases/
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://repo.hortonworks.com/content/repositories/releases/
Downloading: http://repo.hortonworks.com/content/repositories/releases/org/apache/flume/flume-ng-core/1.4.0.2.0.10.1-3/flume-ng-core-1.4.0.2.0.10.1-3.pom
[DEBUG] Writing tracking file /root/.m2/repository/org/apache/flume/flume-ng-core/1.4.0.2.0.10.1-3/flume-ng-core-1.4.0.2.0.10.1-3.pom.lastUpdated
[DEBUG] Using transporter WagonTransporter with priority -1.0 for https://repo.maven.apache.org/maven2
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for https://repo.maven.apache.org/maven2 via xyzproxy.test.co.in:8080 with username=proxy_user_name, password=***
Downloading: https://repo.maven.apache.org/maven2/org/apache/flume/flume-ng-core/1.4.0.2.0.10.1-3/flume-ng-core-1.4.0.2.0.10.1-3.pom
[DEBUG] Writing tracking file /root/.m2/repository/org/apache/flume/flume-ng-core/1.4.0.2.0.10.1-3/flume-ng-core-1.4.0.2.0.10.1-3.pom.lastUpdated

那么什么是确保Maven将为每个HTTP请求使用给定代理的解决方案?该HTTP请求可以是项目pom.xml中的任何存储库集。这里可以从外部访问HTTP URL,以便存在pom文件。

我尝试在settings.xml中为同一个hortonworks存储库添加镜像,以便Maven在查看镜像站点时使用代理详细信息。但这也行不通。

  <mirror>
      <id>hortonworks</id>
      <mirrorOf>HDPReleases</mirrorOf>
      <name>using Mirror for hortonworks.</name>
      <url>http://repo.hortonworks.com/content/repositories/releases/</url>
    </mirror>

请注意,我的代理设置正确,Maven正在使用它们从https://repo.maven.apache.org下载其他文件。如果我从设置文件中删除代理,我会明确错误,Maven无法连接到repo。这意味着我使用了正确的settings.xml文件,并且我的代理设置不正确也不是问题。

仅发出Maven未将代理用于远程存储库URL的httpsrequests。

1 个答案:

答案 0 :(得分:1)

我可以解决这个问题。我知道这是我公司代理的问题,所以最初我在Maven settings.xml中添加了所有必需的代理详细信息和用户名和密码。但是,当我们在pom.xml中定义任何存储库时,没有使用该设置。

因此,对我有用的解决方案是在我的VM上设置CNTLM,然后将settings.xml中的代理指向localhost:3128。之后,来自该VM的任何https请求都转到localhost:3128,我的问题就解决了。

maven settings.xml中的条目将是这样的

<proxies>
   <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>localhost</host>
      <port>3128</port>
      <nonProxyHosts>127.0.0.1</nonProxyHosts>
   </proxy>
</proxies>