连接到 repo.maven.apache.org:443 失败

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

我正在尝试从 jenkins 管道构建 spring-boot maven 项目。

错误:

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 目标:

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>

我目前尝试的分辨率:

  1. 通过 jenkins 中的 settings.xml 文件设置组织代理并在管道中使用配置。

  2. 通过 Maven 目标设置代理:clean install -DproxySet=true -DproxyHost=proxy.com -DproxyPort=xxxxx.

  3. Omitting/Changing relativePath 标签在 pom.xml 到 <relativePath>../pom.xml</relativePath> 和少数其他变体中。

  4. 删除项目的 jenkins 工作区并重新构建它。

  5. 在构建之前向 Maven 中央仓库发出 curl 请求以检查连接建立:curl -I -x proxy.com:xxxxx "https://repo.maven.apache.org/maven2"。连接已建立,但在构建过程中失败。

我打赌你错过了一些配置代理设置的东西。例如设置了错误的协议或者你 misspelled/misplaced setting.xml 文件中的 proxies 标签。

这是 Apache 手册中的示例:

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

该协议似乎是代理服务器的协议,而不是代理请求的协议。下面是关于这一点的长篇讨论:

也有可能你的 setting.xml 放错了地方。这是默认位置:

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

IDE 或 CD/CI 管道可以覆盖默认位置。可以这样做:

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

另一个问题可能是与 JVM 代理配置冲突。我不确定,哪个配置优先。 JVM 使用自己的参数:

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

此处 httphttps 是代理请求的协议(至少 AFAIU)

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

另一个可能的问题是参数 -Djava.net.useSystemProxies。如果设置为 true(默认 - false),则使用操作系统范围的代理配置。

虽然 30thh 的回答对故障排除绝对有帮助,但作为最后的手段,我只是将一个工作的 VM 克隆到一个新实例,在那里创建了我的管道,并且在第一次尝试时它就像一个魅力。所以很明显这与之前的 VM/jenkins.

proxy/firewall 有关