Reputation: 21
I have searched extensively for the answer to this question. I have extensive knowledge of Maven, but am pretty new to Gradle. I am using Intellij 2019.2 Ultimate. I have my build.gradle set up like so:
plugins {
id 'java'
id 'org.springframework.boot' version '2.2.6.RELEASE'
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
dependencies {
implementation 'org.springframework.boot:spring-boot-dependencies:2.2.6.RELEASE'
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs << '-Xlint:unchecked'
options.deprecation = true
}
compileJava {
options.incremental = true
options.fork = true
options.failOnError = false
}
compileTestJava {
options.incremental = true
options.fork = true
options.failOnError = false
}
springBoot {
mainClassName = "com.app.StartMain"
}
bootWar {
manifest {
attributes 'Start-Class': 'com.app.StartMain'
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
I would have thought from this that Gradle would download ALL dependencies in the spring-boot-dependencies-2.2.6.pom file and place in my external dependencies tree in Intellij. But this is not happening. There are a TON of dependencies in that file and I just thought that is how it would behave. Am I missing something in my build file?
Thanks in advance!
Upvotes: 2
Views: 3496
Reputation: 7598
The spring-boot-dependencies
module is a BOM (bill-of-materials) that contains a curated list of module and library versions that are compatible with Spring Boot. But it only advises on which version to use and doesn't actually make your project depend on them. If you open the POM file for it (here is the one for Spring Boot 2.2.6), you will see that they are all in a <dependencyManagement>
block. If they were declared as actual dependencies, they would be in a <dependencies>
block directly under the project root. This behaviour is the same for both Maven and Gradle.
I don't think there is an "all" library where you get all those dependencies in your project. But it would also be bad practice as you are unlikely to need them all. Instead, you should use the Spring Boot Starters that makes sense for you.
And even though the current documentation in Spring Boot tells you differently, I would suggest you don't use the io.spring.dependency-management
plugin as it configures dependencies in a way that is not standard in Gradle, which can lead to confusion. It was created at a time where Gradle didn't support importing BOM files natively, but it does now. Here is a way to declare dependencies without it:
dependencies {
implementation platform("org.springframework.boot:spring-boot-dependencies:2.2.6-RELEASE") // Import the BOM
implementation "org.springframework.boot"spring-boot-starter" // Use a Spring Boot starter (and not that there is no version defined)
}
Upvotes: 3