gradle error Could not find method dependencyManagement()

Viewed 36422

Below is my 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')
}

I was using gradle 2.14 and got the below error

> 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

Then I upgraded gradle to 3.4 as suggested in the error message.

Now I get the below error

Could not find method dependencyManagement() for arguments [build_79bcact4bkf1 sckkod1j3zl7l$_run_closure1@4a2d71c9] on root project 'myproject' of type org.gradle.api.Project.

Is the method dependencyManagement() no longer available in gradle 3.4 ? If anybody is aware of the alternate method to be used in gradle 3.4 , kindly revert

3 Answers

For me the fix was replacing the distributionUrl in the gradle-wrapper.properties with:

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

and updating the dependencies in the build.gradle file to:

dependencies { classpath "com.android.tools.build:gradle:7.0.4" }

In Gradle 7 this error is also caused by importing a BOM using:

dependencyManagement {
    imports {
        mavenBom "tech.jhipster:jhipster-dependencies:${jhipsterDependenciesVersion}"
    }
}

In Gradle 7 you need to import your BOM in the following way:

implementation platform("tech.jhipster:jhipster-dependencies:${jhipsterDependenciesVersion}")
Related