【问题标题】:compile find a bad version of gradle编译找到一个坏版本的gradle
【发布时间】:2018-05-25 16:13:42
【问题描述】:

我使用spring boot 2。在一个多java项目中。

我尝试构建我的主库(还没有 java 文件)

apply plugin: 'java-library-distribution'


plugins {
    id 'org.springframework.boot' version '2.0.0.M7'
}

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}


dependencies {
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.0.0.M7'
    compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
        testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.0.0.M7'
}

distributions {
    main{
        baseName = 'common-model'
    }
}

sourceCompatibility = 1.8

tasks.withType(JavaCompile) {
    options.compilerArgs = ["-Xlint:unchecked", "-Xlint:deprecation", "-parameters"]
}

在我的 gradle/wrapper 中,我有

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2-bin.zip

我得到的错误

由:org.gradle.api.internal.plugins.PluginApplicationException 引起: 应用插件失败[id 'org.springframework.boot']

原因:org.gradle.api.GradleException:Spring Boot 插件需要 Gradle 4.0 或更高版本。当前版本是 Gradle 2.13

我没有找到任何 2.13 版本

在我的主要项目中

buildscript {
    ext {
        springBootVersion = '2.0.0.M7'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

mainClassName = 'com.zirgon.EmailApplication'

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

tasks.withType(JavaCompile) {
    options.compilerArgs = ["-Xlint:unchecked", "-Xlint:deprecation", "-parameters"]
}

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')

    compile project(':common-model')
    compile('org.springframework.boot:spring-boot-starter-mail')

    compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

【问题讨论】:

  • 可以在构建文件中添加println "Gradle version: "+GradleVersion.current().getVersion()确认版本
  • 2.13...奇怪的是我在我的 .gradle/wrapper/dists/gradle-2.13-bin/ 中删除了 2.13 ...当我重新加载项目时...我似乎再次下载了 2.13
  • 没有访问系统很难说,但有几个想法。 zipStorePath 中有旧的 2.13 版本吗?你可以在 gradle 文件中添加一个包装器任务吗? task wrapper(type: Wrapper) { gradleVersion = '4.2' }

标签: spring-boot gradle


【解决方案1】:

您可能会在本地安装 gradle 而不是使用包装器来构建项目,即使用 gradle build 而不是 ./gradlew build

【讨论】:

  • 你救了我!多谢。它解决了我的问题,我也遇到了同样的问题。
【解决方案2】:

这些是我为解决相同问题而采取的步骤。

  1. 我有一个带有 build.gradle 文件的新项目,但我的项目目录中没有 gradle 包装器的副本。我认为这导致使用我的 IDE 的默认 gradle 版本 (IntelliJ),这是一个旧版本。
  2. 我的系统上已经安装了 Gradle。
  3. 在我的项目目录中运行“gradle wrapper”。
  4. 编辑了 ./gradle/wrapper/gradle-wrapper.properties 并确保“distributionUrl”指向我想要的 gradle 版本(在我的例子中是 4.6)。
  5. 重新运行我的构建,然后下载并安装了正确的版本。问题已解决。

我希望这对某人有帮助!

我从另一个项目复制了我的 gradle wrapper 文件夹,并编辑了 ./gradle/wrapper/gradle-wrapper.properties

【讨论】:

    【解决方案3】:

    我正在运行 Eclipse 2018-2019/STS 4.0/Buildship Gradle 3.0。我通过配置 Eclipse > Gradle > Properties 解决了这个问题。

    具体来说:

    1. Eclipse > Gradle > 更新 Gradle 项目 >

      Error: Spring Boot plugin requires Gradle 4.0 or later. The current version is Gradle 3.4.1
      
    2. 看起来Eclipse > Window > Installed Software 中一切正常 所以我检查了我的 Windows 用户配置文件目录:

      Directory of C:\Users\paulsm\.gradle\wrapper\dists
        06/11/2017  09:14 AM    <DIR>          gradle-3.3-all
        12/07/2018  06:23 PM    <DIR>          gradle-3.4.1-bin <-- Eclipse using this version
        11/01/2018  02:38 PM    <DIR>          gradle-4.1-all
        11/01/2018  02:50 PM    <DIR>          gradle-4.4-all
        12/07/2018  03:02 PM    <DIR>          gradle-4.8.1-bin
      
    3. Eclipse > Window > Preferences > Gradle > Gradle distribution > 从“Gradle wrapper”=>“Specific version: 4.8.1”改变

    1. 重新运行 Eclipse > Gradle > 更新 Gradle 项目 => 成功

    2. 这实际上忽略了项目的本地 gradle 包装器设置,并确保我的 Eclipse 项目将拥有“正确的*设置”。所有

      如果我需要的话,我总是可以在每个项目的基础上重新配置 Gradle(恢复到 3.4.1 或更早版本)。

    【讨论】:

      【解决方案4】:

      另一种选择是更改 Gradle 包装器属性。

      错误信息:

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

      更改 gradle-wrapper.properties(位于 /gradle/wrapper/)中的 distributionUrl 值:

      distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip
      

      distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip
      

      【讨论】:

        【解决方案5】:

        打开 gradle/wrapper/gradle-wrapper.properties 并将 distributionUrl 属性更改为 4.6 版本或更高版本。

        distributionBase=GRADLE_USER_HOME
        distributionPath=wrapper/dists
        zipStoreBase=GRADLE_USER_HOME
        zipStorePath=wrapper/dists
        distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-08-18
          • 1970-01-01
          • 1970-01-01
          • 2016-11-21
          • 2018-05-20
          • 2021-01-30
          • 2018-01-11
          相关资源
          最近更新 更多