You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins部署OpenShift时Gradle遇Maven仓库连接超时错误

问题:Jenkins流水线部署至OpenShift时Gradle构建依赖解析超时

运行Jenkins流水线将应用部署到OpenShift时,Gradle构建失败,无法解析org.springframework.boot:spring-boot-gradle-plugin:2.7.7等依赖,核心表现为连接repo.maven.apache.org:443超时。本地运行该应用完全正常。

错误信息

Welcome to Gradle 7.0!
Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'Auth-mapper'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:2.7.7.
  Required by:
      project :
   > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:2.7.7.
      > Could not get resource 'https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/2.7.7/spring-boot-gradle-plugin-2.7.7.pom'.
         > Could not GET 'https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/2.7.7/spring-boot-gradle-plugin-2.7.7.pom'.
            > Connect to repo.maven.apache.org:443 [repo.maven.apache.org/146.75.32.215] failed: connect timed out
> Could not resolve io.spring.gradle:dependency-management-plugin:1.1.0.
  Required by:
      project :
   > Could not resolve io.spring.gradle:dependency-management-plugin:1.1.0.

build.gradle配置

buildscript {
   repositories {
       mavenCentral()
       maven {
       url "https://plugins.gradle.org/m2/"
      }
   }
   dependencies {
   classpath "org.springframework.boot:spring-boot-gradle-plugin:2.7.7"
   classpath "io.spring.gradle:dependency-management-plugin:1.1.0"
   classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.0"  
 }
apply plugin: "org.springframework.boot"
apply plugin: "io.spring.dependency-management"
apply plugin: "org.sonarqube"

解决方案

  • 检查OpenShift构建节点网络连通性:进入OpenShift的Jenkins构建Pod,执行curl -v https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/2.7.7/spring-boot-gradle-plugin-2.7.7.pom测试是否能访问目标地址。如果是网络策略限制,需要调整OpenShift网络规则,允许构建Pod访问外部HTTPS端口。
  • 替换为内部Maven镜像仓库:如果无法直接访问mavenCentral,把buildscript里的mavenCentral()替换成企业内部的镜像仓库(比如Nexus、Artifactory),示例:
    buildscript {
        repositories {
            maven { url "http://your-internal-mirror/repository/maven-public/" }
            maven { url "https://plugins.gradle.org/m2/" }
        }
        dependencies {
            classpath "org.springframework.boot:spring-boot-gradle-plugin:2.7.7"
            classpath "io.spring.gradle:dependency-management-plugin:1.1.0"
            classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.0"  
        }
    }
    apply plugin: "org.springframework.boot"
    apply plugin: "io.spring.dependency-management"
    apply plugin: "org.sonarqube"
    
  • 调整Gradle超时参数:在构建命令中添加--timeout=120000(设置2分钟超时),或者在build.gradle里配置仓库超时:
    buildscript {
        repositories {
            mavenCentral {
                url "https://repo.maven.apache.org/maven2/"
                content {
                    timeout = 60000 // 60秒超时
                }
            }
            maven { url "https://plugins.gradle.org/m2/" }
        }
        // 依赖部分不变
    }
    
  • 检查Jenkins代理配置:如果Jenkins使用了代理,确认代理地址、端口、认证信息正确,并且允许访问repo.maven.apache.org。可以在Jenkins全局配置中调整代理规则,或者在构建任务中添加代理相关参数。

内容的提问来源于stack exchange,提问作者Pracheer Pancholi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 19:05:46