Connect to repo.maven.apache.org:443 failed

Viewed 4060

I'm trying to build a spring-boot maven project from a jenkins pipeline.

Error:

ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for xxx.xxxxx.xxxx:finance-portal:0.0.1-SNAPSHOT: 
 Failure to transfer org.springframework.boot:spring-boot-starter-parent:pom:2.4.2 
 Original error: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.4.2 
 from/to central (https://repo.maven.apache.org/maven2): 
 Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.24.215] failed: 
 Connection refused (Connection refused) and 'parent.relativePath' points at no local POM @ line 6, column 10

maven goal:

clean install -U -X

pom.xml:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.2</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

The resolutions I tried so far:

  1. Setting up org proxy through settings.xml file in jenkins and use the config in the pipeline.

  2. Setting up proxies through maven goal: clean install -DproxySet=true -DproxyHost=proxy.com -DproxyPort=xxxxx.

  3. Omitting/Changing relativePath tag in pom.xml to <relativePath>../pom.xml</relativePath> and few other variants.

  4. Remove jenkins workspace for the project and re-build it.

  5. make a curl request to maven central repo before the build to check connection establishment: curl -I -x proxy.com:xxxxx "https://repo.maven.apache.org/maven2". The connection gets established but fails in the build process.

2 Answers

I bet you missed something configuring the proxy setting. For example set up the wrong protocol or you misspelled/misplaced the proxies tag in the setting.xml file.

Here is an example from Apache manual:

<settings>
  .
  <proxies>
   <proxy>
      <id>example-proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.example.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
    </proxy>
  </proxies>
  .
</settings>

The protocol seems to be a protocol of the proxy server, not of the proxied request. Here is a long discussion about this point:

How to configure a proxy server for both HTTP and HTTPS in Maven's settings.xml?

It is also possible your setting.xml was placed on the wrong place. Here is the default location:

(Linux) /home/bob/.m2/settings.xml
(Windows) C:\Users\bob\.m2\settings.xml

IDE or CD/CI pipeline could override the default location. It can be done like this:

mvn --settings your_location/settings.xml clean install
(or) 
mvn -s your_location/settings.xml clean install

Another problem could be the conflict with JVM proxy configuration. I am not sure, which configuration has priority. JVM uses its own arguments:

http.proxyHost (default: <none>) 
http.nonProxyHosts (default: localhost|127.*|[::1])
http.proxyPort (default: 80)
https.proxyHost(default: <none>)
https.proxyPort (default: 443)

Here http and https are protocols of the proxied request (at least AFAIU)

https://docs.oracle.com/javase/8/docs/api/java/net/doc-files/net-properties.html

One more possible problem could be the argument -Djava.net.useSystemProxies. If it is set to true (default - false) the operation system wide proxy configuration is used.

While 30thh's answer was definitely helpful for troubleshooting, as a last resort I just cloned a working VM to a new instance, created my pipeline there and it worked like a charm in the first attempt. So it's pretty evident that it was something to do with proxy/firewall of the previous VM/jenkins.

Related