Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Gradle 5.1 "implementation platform" instead of Spring Dependency Management Plugin

I have written a Gradle Plugin that contains a bunch of common setup configuration so that all of our projects just need to apply that plugin and a set of dependencies. It uses the Spring Dependency Management Plugin to setup the BOM imports for Spring as shown in the code snippet below:

trait ConfigureDependencyManagement {
    void configureDependencyManagement(final Project project) {
        assert project != null

        project.apply(plugin: "io.spring.dependency-management")

        final DependencyManagementExtension dependencyManagementExtension = project.extensions.findByType(DependencyManagementExtension)
        dependencyManagementExtension.imports {                 
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE"
        }
     }
  }

Whilst that still works in Gradle 5.1 I wanted to replace the Spring Dependency Management Plugin with the new dependency mechanism for BOM Imports so I updated the above to now be this:

trait ConfigureDependencyManagement {
    void configureDependencyManagement(final Project project) {
        assert project != null

        project.dependencies.platform("org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE")
    }
}

Unfortunately that change means none of the dependencies defined by these BOMs are being imported and I get errors like these when building projects?

Could not find org.springframework.boot:spring-boot-starter-web:. Required by: project :

Could not find org.springframework.boot:spring-boot-starter-data-jpa:. Required by: project :

Could not find org.springframework.boot:spring-boot-starter-security:. Required by: project :

Am I correct in thinking the Spring Dependency Management Plugin is no longer needed with Gradle 5.1 and if so then am I missing something for this to work?

like image 677
Shane Rowatt Avatar asked Jan 06 '19 12:01

Shane Rowatt


People also ask

Can Gradle be used for dependency management in spring boot?

The Spring Boot Gradle Plugin provides Spring Boot support in Gradle. It allows you to package executable jar or war archives, run Spring Boot applications, and use the dependency management provided by spring-boot-dependencies .

Is Gradle a dependency management tool?

Gradle has built-in support for dependency management and lives up to the task of fulfilling typical scenarios encountered in modern software projects.


1 Answers

The platform support in Gradle 5 can replace the Spring dependency management plugins for BOM consumption. However the Spring plugin offers features that are not covered by the Gradle support.

Regarding your issue, the problem comes from the following line:

project.dependencies.platform("org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE")

This will simply create a Dependency, it still needs to be added to a configuration. by doing something like:

def platform = project.dependencies.platform("org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE")
project.dependencies.add("configurationName", platform)

where configurationName is the name of the configuration that requires the BOM. Note that you may have to add this BOM to multiple configurations, depending on your project.

like image 161
Louis Jacomet Avatar answered Sep 28 '22 01:09

Louis Jacomet