12

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?

1 Answer 1

12

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.

Sign up to request clarification or add additional context in comments.

2 Comments

gradle does not support overriding versions and add external (dependency that not declared in the BOM) dependency version, am I correct? (enforcedPlatform is not what my need is)
github.com/gradle/gradle/issues/9160 - okay, we have to wait :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.