Gradle项目构建失败求助:Spring Boot新手遇ArchivePublishArtifact错误
Spring Boot Gradle构建失败:错误原因与修复方案
错误原因
你使用的Spring Boot 2.1.7.RELEASE仅兼容Gradle 4.x~5.x版本,若IntelliJ配置了Gradle 6.x及以上版本,就会触发这个构造函数不匹配的错误——Gradle 6+重构了ArchivePublishArtifact的初始化逻辑,旧版Spring Boot插件无法适配该变化。另外,jcenter()仓库已停止服务,继续使用可能导致依赖拉取失败。
修复方案
方案一:升级Spring Boot版本(推荐)
升级到兼容高版本Gradle的Spring Boot版本(如2.3.x及以上),同时更新Gradle依赖声明语法(compile/testCompile已被implementation/testImplementation取代):
修改后的build.gradle代码:
buildscript { ext { springBootVersion = '2.3.12.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' repositories { mavenCentral() } dependencies { implementation('org.springframework.boot:spring-boot-starter-web') testImplementation('org.springframework.boot:spring-boot-starter-test') }
方案二:降级Gradle版本
如果不想升级Spring Boot,可将Gradle版本降级到5.x(如5.6.4):
- 打开项目下的
gradle/wrapper/gradle-wrapper.properties文件 - 修改
distributionUrl为:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
验证操作
修改完成后,在IntelliJ中点击「Refresh Gradle Project」按钮,重新构建项目即可。
内容的提问来源于stack exchange,提问作者javanewbie
相关产品推荐
相关产品推荐

