首页 > 解决方案 > springboot中使用gradle时,加载依赖遇到sun.security.validator.validatorexception。我不知道如何解决

问题描述

我正在使用gradle构建springboot项目,但是gradle加载依赖总是不好。错误如下:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'server'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:2.2.2.RELEASE.
     Required by:
         project :
      > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:2.2.2.RELEASE.
         > Could not get resource 'http://maven.aliyun.com/nexus/content/groups/public/org/springframework/boot/spring-boot-gradle-plugin/2.2.2.RELEASE/spring-boot-gradle-plugin-2.2.2.RELEASE.pom'.
            > Could not GET 'https://maven.aliyun.com/nexus/content/groups/public/org/springframework/boot/spring-boot-gradle-plugin/2.2.2.RELEASE/spring-boot-gradle-plugin-2.2.2.RELEASE.pom'.
               > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

我尝试在Java证书库中添加相应的证书,但是没有用。我现在可以直接在浏览器上下载,但是不能使用gradle添加依赖。希望能得到帮助,谢谢。

我的配置如下:

buildscript {
    ext {
        springBootVersion = '2.2.2.RELEASE'
    }
    repositories {
        maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.cqut.spider'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web' 
    implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.0'
    testImplementation 'org.springframework.boot:spring-boot-starter-test' 
    implementation 'com.squareup.okhttp3:okhttp:3.12.1'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation  group: 'mysql', name: 'mysql-connector-java', version: '8.0.15'
    implementation 'com.github.pagehelper:pagehelper-spring-boot-starter:1.2.5'

    runtimeOnly('mysql:mysql-connector-java')
    compile 'tk.mybatis:mapper-spring-boot-starter:1.1.5'
    compile "net.sf.json-lib:json-lib:2.4:jdk15"

}

标签: springspring-bootgradle

解决方案


如果您使用 访问 maven.aliyun.com http,您将被重定向到https,这很好,现在绝大多数存储库都在这样做。您的构建文件仍然有一个http存储库,您需要将其更改为https,我猜错误会消失。


推荐阅读