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

Gradle构建失败:无法解析org.wso2.apache.httpcomponents:httpclient依赖

问题:Gradle构建时无法解析WSO2定制HttpClient依赖

在Java项目中执行gradle build或gradle buildDependencies任务时,添加依赖implementation group: 'org.wso2.apache.httpcomponents', name: 'httpclient', version: '4.3.1.wso2v1'后编译失败,提示无法解析:compileClasspath配置的所有文件,当前配置的所有Maven仓库都找不到该依赖的pom文件,本地Gradle缓存中没有这个依赖,但存在其他相关依赖。


错误日志

> Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not resolve org.wso2.apache.httpcomponents:httpclient:4.3.1.wso2v1.
     Required by:
         project :
      > Could not resolve org.wso2.apache.httpcomponents:httpclient:4.3.1.wso2v1.
         > Could not get resource 'https://repo.maven.apache.org/maven2/org/wso2/apache/httpcomponents/httpclient/4.3.1.wso2v1/httpclient-4.3.1.wso2v1.pom'.
            > Could not GET 'https://repo.maven.apache.org/maven2/org/wso2/apache/httpcomponents/httpclient/4.3.1.wso2v1/httpclient-4.3.1.wso2v1.pom'.
               > repo.maven.apache.org
      > Could not resolve org.wso2.apache.httpcomponents:httpclient:4.3.1.wso2v1.
         > Could not get resource 'https://splunk.jfrog.io/splunk/ext-releases-local/org/wso2/apache/httpcomponents/httpclient/4.3.1.wso2v1/httpclient-4.3.1.wso2v1.pom'.
            > Could not GET 'https://splunk.jfrog.io/splunk/ext-releases-local/org/wso2/apache/httpcomponents/httpclient/4.3.1.wso2v1/httpclient-4.3.1.wso2v1.pom'.
               > splunk.jfrog.io
      > Could not resolve org.wso2.apache.httpcomponents:httpclient:4.3.1.wso2v1.
         > Could not get resource 'https://repo.spring.io/plugins-release/org/wso2/apache/httpcomponents/httpclient/4.3.1.wso2v1/httpclient-4.3.1.wso2v1.pom'.
            > Could not GET 'https://repo.spring.io/plugins-release/org/wso2/apache/httpcomponents/httpclient/4.3.1.wso2v1/httpclient-4.3.1.wso2v1.pom'.
               > repo.spring.io
      > Could not resolve org.wso2.apache.httpcomponents:httpclient:4.3.1.wso2v1.
         > Could not get resource 'https://artifactory.devcloud.com/artifactory/org/wso2/apache/httpcomponents/httpclient/4.3.1.wso2v1/httpclient-4.3.1.wso2v1.pom'.
            > Could not GET 'https://artifactory.devcloud.com/artifactory/org/wso2/apache/httpcomponents/httpclient/4.3.1.wso2v1/httpclient-4.3.1.wso2v1.pom'.
               > artifactory.devcloud.com
      > Could not resolve org.wso2.apache.httpcomponents:httpclient:4.3.1.wso2v1.
         > Could not get resource 'https://repo.spring.io/release/org/wso2/apache/httpcomponents/httpclient/4.3.1.wso2v1/httpclient-4.3.1.wso2v1.pom'.
            > Could not GET 'https://repo.spring.io/release/org/wso2/apache/httpcomponents/httpclient/4.3.1.wso2v1/httpclient-4.3.1.wso2v1.pom'.
               > repo.spring.io
      > Could not resolve org.wso2.apache.httpcomponents:httpclient:4.3.1.wso2v1.
         > Could not get resource 'https://repository.jboss.org/maven2/org/wso2/apache/httpcomponents/httpclient/4.3.1.wso2v1/httpclient-4.3.1.wso2v1.pom'.
            > Could not GET 'https://repository.jboss.org/maven2/org/wso2/apache/httpcomponents/httpclient/4.3.1.wso2v1/httpclient-4.3.1.wso2v1.pom'.
               > repository.jboss.org

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
1 actionable task: 1 executed

build.gradle配置

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.7.1'
    }
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.webhosting.broker'
version = '0.0.1-SNAPSHOT'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

repositories {
    mavenCentral()
    
    maven { 
        url "https://splunk.jfrog.io/splunk/ext-releases-local" 
    }
    
    maven { 
        url "https://repo.spring.io/plugins-release" 
    }
    
    maven { 
        url "https://artifactory.devcloud.com/artifactory/" 
    }
    
    maven {
        url "https://repo.spring.io/release"
    }
    maven {
        url "https://repository.jboss.org/maven2"
    }
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:2021.0.3"
    }
}

dependencies {
    compileOnly "org.projectlombok:lombok"
    implementation "org.springframework.boot:spring-boot-starter-security"
    implementation "org.springframework.boot:spring-boot-starter-webflux"//
    implementation "org.springframework.cloud:spring-cloud-starter-open-service-broker:3.5.2"//
    implementation "org.codehaus.janino:janino:3.1.7"
    runtimeOnly "com.splunk.logging:splunk-library-javalogging:1.11.5"
    implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.10.0'
    
// https://mvnrepository.com/artifact/org.wso2.apache.httpcomponents/httpclient
implementation group: 'org.wso2.apache.httpcomponents', name: 'httpclient', version: '4.3.1.wso2v1'

}

本地Gradle缓存目录

10/01/2023  17:02    <DIR>          ch.qos.logback
10/01/2023  17:02    <DIR>          com.datastax.oss
10/01/2023  17:02    <DIR>          com.fasterxml
10/01/2023  16:52    <DIR>          com.fasterxml.jackson
10/01/2023  16:52    <DIR>          com.fasterxml.jackson.core
10/01/2023  17:02    <DIR>          com.fasterxml.jackson.datatype
10/01/2023  16:52    <DIR>          com.fasterxml.jackson.module
10/01/2023  16:52    <DIR>          com.google.code.findbugs
11/01/2023  11:19    <DIR>          com.google.code.gson
10/01/2023  17:02    <DIR>          com.oracle.database.jdbc
10/01/2023  17:02    <DIR>          com.querydsl
11/01/2023  11:19    <DIR>          com.splunk.logging
10/01/2023  17:02    <DIR>          com.squareup.okhttp3
10/01/2023  17:02    <DIR>          com.squareup.okio
10/01/2023  17:02    <DIR>          commons-beanutils
10/01/2023  16:52    <DIR>          commons-codec
10/01/2023  17:02    <DIR>          commons-collections
10/01/2023  17:02    <DIR>          io.dropwizard.metrics
10/01/2023  17:02    <DIR>          io.fabric8
10/01/2023  17:02    <DIR>          io.github.openfeign
10/01/2023  17:02    <DIR>          io.github.resilience4j
10/01/2023  17:02    <DIR>          io.micrometer
10/01/2023  17:02    <DIR>          io.netty
10/01/2023  17:02    <DIR>          io.projectreactor
10/01/2023  17:02    <DIR>          io.projectreactor.netty
10/01/2023  17:02    <DIR>          io.prometheus
10/01/2023  17:02    <DIR>          io.r2dbc
10/01/2023  17:02    <DIR>          io.rsocket
10/01/2023  16:52    <DIR>          io.spring.gradle
10/01/2023  17:02    <DIR>          io.zipkin.brave
10/01/2023  17:02    <DIR>          io.zipkin.reporter2
10/01/2023  17:02    <DIR>          jakarta.annotation
10/01/2023  17:02    <DIR>          jakarta.validation
10/01/2023  16:52    <DIR>          net.java.dev.jna
13/03/2023  12:51    <DIR>          org.antlr
10/01/2023  16:52    <DIR>          org.apache
10/01/2023  16:52    <DIR>          org.apache.commons
13/03/2023  12:51    <DIR>          org.apache.httpcomponents
10/01/2023  17:02    <DIR>          org.apache.logging
10/01/2023  17:02    <DIR>          org.apache.logging.log4j
10/01/2023  17:02    <DIR>          org.apache.maven
10/01/2023  17:02    <DIR>          org.codehaus.groovy
10/01/2023  17:02    <DIR>          org.codehaus.janino
10/01/2023  17:02    <DIR>          org.eclipse.ee4j
10/01/2023  17:02    <DIR>          org.eclipse.jetty
10/01/2023  17:02    <DIR>          org.glassfish.jersey
10/01/2023  17:02    <DIR>          org.hibernate.validator
10/01/2023  17:02    <DIR>          org.infinispan
10/01/2023  17:02    <DIR>          org.jboss
10/01/2023  17:02    <DIR>          org.jboss.arquillian
10/01/2023  17:02    <DIR>          org.jboss.logging
10/01/2023  17:02    <DIR>          org.jboss.shrinkwrap
10/01/2023  17:02    <DIR>          org.jboss.shrinkwrap.descriptors
10/01/2023  17:02    <DIR>          org.jboss.shrinkwrap.resolver
10/01/2023  17:02    <DIR>          org.jetbrains
10/01/2023  17:02    <DIR>          org.jetbrains.kotlin
10/01/2023  17:02    <DIR>          org.jetbrains.kotlinx
10/01/2023  17:02    <DIR>          org.junit
10/01/2023  17:02    <DIR>          org.mockito
10/01/2023  17:02    <DIR>          org.projectlombok
10/01/2023  17:02    <DIR>          org.reactivestreams
10/01/2023  17:02    <DIR>          org.slf4j
10/01/2023  16:52    <DIR>          org.sonatype.oss
10/01/2023  17:02    <DIR>          org.springframework
10/01/2023  17:02    <DIR>          org.springframework.boot
10/01/2023  17:02    <DIR>          org.springframework.cloud
10/01/2023  17:02    <DIR>          org.springframework.data
10/01/2023  17:02    <DIR>          org.springframework.integration
10/01/2023  17:02    <DIR>          org.springframework.security
10/01/2023  17:02    <DIR>          org.springframework.session
10/01/2023  16:52    <DIR>          org.tomlj
10/01/2023  17:02    <DIR>          org.yaml

解决方案

问题核心是当前配置的仓库中没有WSO2定制的HttpClient依赖,需添加WSO2官方仓库或手动安装依赖。

方案1:添加WSO2官方仓库

在build.gradle的repositories块中加入WSO2公共仓库:

repositories {
    mavenCentral()
    
    // 新增WSO2仓库
    maven { 
        url "https://maven.wso2.org/nexus/content/groups/wso2-public/" 
    }
    
    // 原有仓库保留
    maven { 
        url "https://splunk.jfrog.io/splunk/ext-releases-local" 
    }
    
    maven { 
        url "https://repo.spring.io/plugins-release" 
    }
    
    maven { 
        url "https://artifactory.devcloud.com/artifactory/" 
    }
    
    maven {
        url "https://repo.spring.io/release"
    }
    maven {
        url "https://repository.jboss.org/maven2"
    }
}

添加完成后,执行清理并重新构建:

./gradlew clean build --refresh-dependencies

方案2:手动安装依赖到本地仓库

若无法访问WSO2公共仓库,可手动下载依赖的jar和pom文件,安装到本地Maven仓库(Gradle会自动读取本地仓库):

mvn install:install-file -Dfile=httpclient-4.3.1.wso2v1.jar -DgroupId=org.wso2.apache.httpcomponents -DartifactId=httpclient -Dversion=4.3.1.wso2v1 -Dpackaging=jar -DpomFile=httpclient-4.3.1.wso2v1.pom

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 04:50:10