首页 > 解决方案 > SpringBoot gradle 插件抱怨“未解决的参考:providedRuntime”

问题描述

我正在关注最新的SpringBoot gradle 插件参考,以便设置一个可以构建 uberjar 的 SpringBoot 项目。

以下是完整内容build.gradle.kts

plugins {
    java
    application
    id("org.springframework.boot") version "2.2.1.RELEASE"
    id("io.spring.dependency-management") version "1.0.8.RELEASE"
}

repositories {
    jcenter()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
    testImplementation("org.testng:testng:6.14.3")
}

application {
    // Define the main class for the application.
    mainClassName = "com.demo.App"
}

val test by tasks.getting(Test::class) {
    // Use TestNG for unit tests
    useTestNG()
}

dependencyManagement {
    imports {
        mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
    }
}

不幸的是,当我运行 gradle 命令时,我收到以下错误:

> Configure project :
e: /Users/xux/Documents/toys/web/build.gradle.kts:15:5: Unresolved reference: providedRuntime

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/xux/Documents/toys/web/build.gradle.kts' line: 15

* What went wrong:
Script compilation error:

  Line 15:     providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
               ^ Unresolved reference: providedRuntime

1 error

我正在使用 Java 1.8.0_201、Gradle 6.0、Kotlin 1.3.50、Mac OS X 10.15.1 x86_64。

标签: spring-bootgradlegradle-kotlin-dslspring-boot-gradle-plugin

解决方案


推荐阅读