Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle error Could not find method dependencyManagement()

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

like image 933
lives Avatar asked Sep 14 '17 08:09

lives


People also ask

What is dependencyManagement in Gradle?

Maven's dependency management includes the concept of a bill-of-materials (bom). A bom is a special kind of pom that is used to control the versions of a project's dependencies and provides a central place to define and update those versions.

How does Gradle find dependencies?

Every Gradle project provides the task dependencies to render the so-called dependency report from the command line. By default the dependency report renders dependencies for all configurations. To focus on the information about one configuration, provide the optional parameter --configuration .

What is DependencyResolutionManagement?

Interface DependencyResolutionManagement @Incubating public interface DependencyResolutionManagement. Allows configuring dependency resolution for all projects of the build.

What is module in Gradle?

A module is an isolated piece of the bigger project. In a multi-module project, these modules have their own jobs but work together to form the whole project. Most Android projects only have one module, the app module. The build. gradle (Module: app) file here is in the app folder.


3 Answers

To use this DSL you have to provide the 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"

Or you can use:

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

More details here.

like image 171
Gabriele Mariotti Avatar answered Oct 08 '22 22:10

Gabriele Mariotti


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}")
like image 25
Joseph Waweru Avatar answered Oct 08 '22 22:10

Joseph Waweru


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" }

like image 22
Juls Avatar answered Oct 09 '22 00:10

Juls