1
votes

I am using Maven to build my code and inside my project pom.xml, I have configured a remote repository as

 <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>

And in Maven setting.xml I have added details under proxy tag so that all HTTPS requests will use proxy while downloading. Then Maven fails to get required files from remote hortonworks repository and fail with error like

[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]

I can understand here what is problem. It is that whenever Maven tries to download from repo.hortonworks.com, it doesn't use proxy details which I have mentioned inside settings.xml and therefore that request is not working. But when it passes same request to Maven

This is clear by looking at debug messages from Maven build as shown below. While downloading anything from https://repo.maven.apache.org, it uses correct proxy details. But when anything to be downloaded from repository of hortonworks, it is failes to use proxy.:

[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

So what is solution to make sure that Maven will use given proxy for each and every HTTP requests? That HTTP request could be to any repository set inside project pom.xml. Here that HTTP URL is accessible from outside so that pom file is present.

I tried adding a mirror for my same hortonworks repository inside setting.xml so Maven will use proxy details while looking at mirror site. But that is also not working.

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

Note that My proxy settings are correct and Maven is using them to download other files from https://repo.maven.apache.org. If I remove the proxy from settings file, I get clear error that Maven is unable to connect to repo. That means I am using correct settings.xml file and it is not issue that my proxy settings are incorrect.

Only issue that Maven is not using proxy for httpsrequests for remote repositories URL.

1
Followers of [hortonworks] and [hortonworks-data-platform] may be interested in a Meta question proposing to move all questions from one to the other.Mogsdad

1 Answers

1
votes

I could solve the issue. I was aware that this was issue my company proxy so initially I had added all required proxy details with username and password in Maven settings.xml. However that setting was not getting used when we define any repository inside pom.xml.

So solution that worked for me is set CNTLM on my VM and then point proxy inside settings.xml as localhost:3128. after that any https request from that VM goes to localhost:3128 and my issue is solved.

Entry in maven settings.xml will be like this

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