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

Java8环境下Spring Boot构建Jar失败求助:runtime配置未找到

问题解决:Spring Boot 1.5.x Gradle构建报错「Configuration with name 'runtime' not found」

错误原因

这个报错的核心是Gradle版本与Spring Boot 1.5.21.RELEASE不兼容:

  • Gradle 7及以上版本移除了旧的runtime依赖配置,统一改用runtimeOnly;
  • 但Spring Boot 1.5.x系列的插件基于旧版Gradle开发,仍会尝试访问已被移除的runtime配置,导致找不到该配置的异常。
  • 另外你的配置里还有一个额外问题:Spring Boot 1.5.x默认集成JUnit 4,而你配置了useJUnitPlatform()(JUnit 5的测试平台),这会导致测试任务执行异常。

解决方案

方案1:降级Gradle到兼容版本(推荐)

Spring Boot 1.5.x最高兼容Gradle 4.x版本,推荐使用Gradle 4.10.3(该版本是Spring Boot 1.5支持的最后一个稳定Gradle版本):

  1. 打开项目根目录下的gradle/wrapper/gradle-wrapper.properties文件
  2. 修改distributionUrl为:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip

方案2:调整Gradle配置适配高版本Gradle(不推荐,存在兼容性隐患)

如果坚持使用高版本Gradle,需要手动添加runtime配置映射,并修正测试任务配置:

plugins {
    id 'java'
    id 'org.springframework.boot' version '1.5.21.RELEASE'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}

// 添加runtime配置映射,兼容高版本Gradle
configurations {
    runtime.extendsFrom runtimeOnly
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
    sourceCompatibility = 1.8
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web:1.5.21.RELEASE'
    // Spring Boot 1.5的test依赖默认是JUnit 4,改用testCompile适配旧版Gradle
    testCompile 'org.springframework.boot:spring-boot-starter-test'

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'org.json:json:20231013'
    implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
    runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
    runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
}

// 改用JUnit 4的默认测试配置
tasks.named('test') {
    useJUnit()
}

关键说明

  • Spring Boot 1.5.x是停止维护多年的老旧版本,若项目允许,建议升级到Spring Boot 2.x+版本,能更好兼容新版Gradle。
  • 选择方案1时,修改Gradle wrapper后,下次构建会自动下载对应版本的Gradle,无需手动安装。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 19:01:08