【问题标题】:Spring Boot plugin requires Gradle 4.10 or later. The current version is Gradle 4.1Spring Boot 插件需要 Gradle 4.10 或更高版本。当前版本是 Gradle 4.1
【发布时间】:2020-04-16 01:41:30
【问题描述】:

我有一个 Spring Gradle 项目。我正在尝试使用gradle build 命令进行构建。但是出现以下错误:

* Where:
Build file 'F:\MyProjectName\build.gradle' line: 2

* What went wrong:
An exception occurred applying plugin request [id: 'org.springframework.boot', version: '2.2.2.RELEASE']
> Failed to apply plugin [id 'org.springframework.boot']
   > Spring Boot plugin requires Gradle 4.10 or later. The current version is Gradle 4.1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

但我已经在使用我正在使用 gradle-5.6.4。并且还尝试了最新的 gradle-6.0.1-bin 但得到了同样的错误。

gradle-wrapper.properties

#Wed Dec 04 12:51:57 IST 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

build.gradle

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

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

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'io.jsonwebtoken:jjwt:0.9.1'
    implementation 'org.springframework.security:spring-security-jwt:1.0.7.RELEASE'
    implementation 'org.springframework.security.oauth:spring-security-oauth2:2.4.0.RELEASE'
    implementation 'de.mkammerer:argon2-jvm:2.6'

    compileOnly 'org.projectlombok:lombok:1.18.10'
    annotationProcessor 'org.projectlombok:lombok:1.18.10'

    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'io.projectreactor:reactor-test'
    testImplementation 'org.springframework.security:spring-security-test'
}

jar {
    enabled true
}

test {
    useJUnitPlatform()
}

如何解决这个问题?提前致谢。

【问题讨论】:

  • 这个链接是什么:distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
  • 这是我的默认gradle-wrapper.properties 文件和distributionUrl

标签: java spring-boot gradle build.gradle gradle-plugin


【解决方案1】:
  1. 打开文件gradle-wrapper.properties
  2. 您会发现 distributionUrl 的值类似于 distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
  3. gradle 版本更改为大于 4.10 ,因为我有 5.6.2

注意,这将升级本地范围的 gradle 版本。 (与系统范围的 gradle 安装相反) 您将不得不使用 gradlew(rapper) 来调用。

例如(基于 linux)

./gradlew 构建

我猜它在 windows 上会很相似

.\gradlew.bat build

你不能使用

gradle build

因为这将调用机器范围的版本(可能是旧版本)

下面的完整本地范围输出:

./gradlew  build

Welcome to Gradle 5.6.2!

Here are the highlights of this release:
 - Incremental Groovy compilation
 - Groovy compile avoidance
 - Test fixtures for Java projects
 - Manage plugin versions via settings script

【讨论】:

    【解决方案2】:

    如果您使用命令gradle build,那么您没有使用包装器,因此没有使用包装器属性中配置的 gradle 版本。您正在使用您机器上安装的全局 gradle 版本。

    要使用 gradle 包装器,请使用

    ./gradlew build
    

    或者,在 Windows 上

    .\gradlew.bat build
    

    在您的项目根文件夹中。

    Documentation.

    【讨论】:

    • 这是一个完全不同的问题。删除您的 jar { enabled true } 部分。
    • 使用./gradlew bootJar 解决了我的问题 :)
    • @Victory 你应该接受这个答案,这是很好的答案;)
    【解决方案3】:

    在我的例子中,原因是一个旧的settings.gradle 驻留在项目的完全不相关的父目录(!)中。

    【讨论】:

      【解决方案4】:

      在我的情况下,同一工作区“.settings/org.eclipse.buildship.core.prefs”文件中的其他项目具有以下属性

      gradle.user.home=C\:/Gradle/gradle-6.7/bin(old version)
      

      替换为以下内容:

      gradle.user.home=C\:/Gradle/gradle-7.3.2/bin(new version)
      

      【讨论】:

        猜你喜欢
        • 2015-11-21
        • 2014-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-28
        • 2016-05-11
        相关资源
        最近更新 更多