【问题标题】:gradle Failed to apply plugin [id 'org.springframework.boot']gradle 无法应用插件 [id 'org.springframework.boot']
【发布时间】:2020-05-18 00:33:47
【问题描述】:

我正在尝试运行 spring-boot 项目。我对gradle有一些问题。

gradle 构建工作正常,但我无法运行 gradlew

无法运行命令: ./gradlew build &&java -jar build/libs/gs-spring-boot-docker-0.1.0.jar

这里是错误:

Failed to apply plugin [id 'org.springframework.boot']
Spring Boot plugin requires Gradle 4.10 or later. The current version is Gradle 4.9

我的 gradle 版本 6.0

我的 gradle 文件

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE")
        classpath('com.google.cloud.tools.jib:com.google.cloud.tools.jib.gradle.plugin:1.8.0')
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.google.cloud.tools.jib'


bootJar {
    baseName = 'gs-spring-boot-docker'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    implementation('org.springframework.boot:spring-boot-starter-data-jpa')
    implementation('org.springframework.boot:spring-boot-starter-web')
    implementation('org.postgresql:postgresql')
    testCompile("org.springframework.boot:spring-boot-starter-test")
}

gradle build 工作正常,没有错误。

【问题讨论】:

  • 项目是否使用了 gradle-wrapper?如果是这样:可能是 gradle-wrapper 使用 gradle-version 4.9 吗?
  • @Turing85 我不知道如何检查它。我试过 $ gradle wrapper --version 它显示了我 gradle 6
  • 进入项目根目录,执行./gradlew --version(或Windows上的gradlew.bat --version)。

标签: java spring-boot ubuntu gradle


【解决方案1】:

Gradle 包装器的全部意义在于在项目中使用固定版本的 Gradle。这可确保您不会意外使用与项目支持的版本不兼容的版本。另一个好处是,如果您还没有正确的版本,它会自动下载它。

当您键入gradle(不带“w”)时,您正在调用您放置在路径中的手动下载分发。这完全跳过了包装部分。在您的情况下,您显然已经下载了版本 6 并更新了项目以使用该版本。

但是,您还没有更新包装脚本,这是您应该做的。如果您查看gradle/wrapper/gradle-wrapper.properties,您应该会看到它设置为 4.9,它不再与您的项目兼容。

要更新它,您需要运行以下命令两次

gradlew wrapper --gradle-version 6.1.1 --distribution-type all(假设您需要 6.1.1 版本,这是撰写本文时的最新版本。)

第一次运行时,它基本上只会更改gradle-wrapper.properties 中的版本(例如更改为 6.1.1)。如果由于包装器与项目相比太旧而导致失败,只需使用文本编辑器手动更改文件即可。

第二次运行时,Gradle 将使用该新版本(例如 6.1.1)启动,并在需要时自行更新包装脚本。

另外,如果您想在开发期间启动 Spring Boot 应用程序,只需运行 gradlew bootRun。无需手动构建jar和调用java。

此外,在您的依赖项中使用 implementation 而不是 compile。前者已弃用(包括testCompile)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 2019-08-04
    • 2019-07-16
    • 2019-01-13
    • 2019-10-04
    • 2020-03-06
    • 2016-10-04
    相关资源
    最近更新 更多