2017-09-14 314 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) –

相關問題