gradle error无法找到方法dependencyManagement()

liv*_*ves 13 gradle build.gradle

下面是我的build.gradle

buildscript {
    ext {
        springBootVersion = '2.0.0.M3'
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}


apply plugin: 'org.springframework.boot'
apply plugin: 'maven-publish'

dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.SR7'
    }
}

dependencies {


    compile("org.springframework.cloud:spring-cloud-starter-eureka")
    compile "org.elasticsearch:elasticsearch:5.5.0"

    testCompile('org.springframework.boot:spring-boot-starter-test')
}
Run Code Online (Sandbox Code Playgroud)

我使用gradle 2.14并得到以下错误

> Failed to apply plugin [id 'org.springframework.boot']
   > Spring Boot plugin requires Gradle 3.4 or later. The current version is Gra
dle 2.14
Run Code Online (Sandbox Code Playgroud)

然后我按照错误消息中的建议将gradle升级到3.4.

现在我得到以下错误

无法在类型为org.gradle.api.Project的根项目"myproject"上找到参数[build_79bcact4bkf1 sckkod1j3zl7l $ _run_closure1 @ 4a2d71c9]的方法dependencyManagement().

方法dependencyManagement()在gradle 3.4中不再可用吗?如果有人知道在gradle 3.4中使用的替代方法,请回复

Gab*_*tti 21

要使用它,DSL您必须提供dependency-management-plugin:

buildscript {
  repositories {
    maven {
      jcenter() //or mavenCentral()
    }
  }
  dependencies {
    classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
  }
}

apply plugin: "io.spring.dependency-management"
Run Code Online (Sandbox Code Playgroud)

或者您可以使用:

plugins {
    id "io.spring.dependency-management" version "1.0.3.RELEASE"
}
Run Code Online (Sandbox Code Playgroud)

更多细节在这里.

  • 对于最近从Spring Boot 1.x升级到2.x的任何人:您不需要在Spring Boot 1.x中单独应用依赖关系管理插件.这在Spring Boot 2.x中有所改变,如[此处](https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#dependency-management) (3认同)