buildscript {
ext {
springBootVersion = '2.2.4.RELEASE'
repositories {
mavenCentral()
plugins {
id 'java'
id 'org.springframework.boot' version "${springBootVersion}"
dependencies {
implementation platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
–
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.
The key point to note is, apart from providing Spring Boot support, it enables the use of dependency management through spring-boot-dependencies. But...
Why Spring Dependency Management Plugin
The spring-boot-dependencies BOM enables dependency management.
Which means:
IF you omit the version for a dependency you declare:
AND it is a managed dependency (ie listed in the BOM with version):
THEN (provided you apply the spring-boot-dependencies plugin) you get to enjoy dependency management like in Maven
To get the dependencies bom in your project you have to apply the dependency-management plugin in concert with the Spring boot gradle plugin. Again to paraphrase
When you apply the io.spring.dependency-management plugin, Spring
Boot’s plugin will automatically import the spring-boot-dependencies
bom from the version of Spring Boot that you are using.
Why one or the other?
If you need Spring Boot support, you want that plugin.
In addition, if you want managed dependencies (as explained above), you want the dependency-management plugin.
Another way to have dependency constraints
The dependency-management plugin is one way to import the Spring Boot bill of materials (BOM).
Another way (supported by Gradle 5 and up) is to import recommended dependency versions from a BOM as dependency constraints in Gradle. The "platform" (dependency handler method) is used to import the BOM.
dependencies {
// Load BOM for Spring Boot.
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE"))
Using either way of dependency management, you can specify your dependencies without an explicit version, as below:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
Spring Boot’s Gradle plugin no longer automatically applies the dependency management plugin. Instead, Spring Boot’s plugin now reacts to the dependency management plugin being applied by importing the correct version of the spring-boot-dependencies BOM. This gives you more control over how and when dependency management is configured.
For most applications applying the dependency management plugin will be sufficient:
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management' // <-- add this to your build.gradle
Note:
The dependency management plugin remains a transitive dependency of spring-boot-gradle-plugin so there’s no need for it to be listed as a classpath dependency in your buildscript configuration.
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#dependency-management
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.