2017-09-14 312 views
4

下面是我的build.gradlegradle这个错误找不到方法dependencyManagement()

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') 
} 

我使用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 

然后我升级到gradle这个3.4的建议在错误信息中。

现在,我得到下面的错误

找不到方法dependencyManagement()为参数[build_79bcact4bkf1 sckkod1j3zl7l $ @ _run_closure1 4a2d71c9]在根项目 'MyProject的' 类型org.gradle.api.Project的 。

Gradle 3.4中的方法dependencyManagement()不再可用吗? 如果有人知道的另一种方法的gradle这个3.4中使用,请回复

+0

这种方法确实来自gradle这个本身,而是来自春天的插件。看看这里:https://github.com/spring-gradle-plugins/dependency-management-plugin – Opal

回答

4

要使用此DSL你必须提供的依赖管理,插件:

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

apply plugin: "io.spring.dependency-management" 

或者你可以使用:

plugins { 
    id "io.spring.dependency-management" version "1.0.3.RELEASE" 
} 

更多details here.

+0

对于最近从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) –

相关问题