Gradle Spring Boot plugin


(sergey.morenets) #1

Hi

I generated and downloaded sample Spring boot application from http://start.spring.io/ and it worked fine. However I couldn’t understand which plugin is responsible for pure dependency management.

All I want is to automatically resolve dependency versions. So I tried this build. gradle:

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

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'io.spring.dependency-management'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
	mavenCentral()
}

dependencies {
	compile('org.springframework.boot:spring-boot-starter-web')
	testCompile('org.springframework.boot:spring-boot-starter-test')
}

However I’ve got exception:

* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not find org.springframework.boot:spring-boot-starter-web:.
  Required by:
      project :

So is it possible to get automatic dependency managemen without Spring Boot plugin?

Thanks


(James Justinic) #2

You don’t need the Spring Boot plugin, but the dependency versions have to come from somewhere. Your options with the Spring Dependency Management plugin are to declare them in the dependencyManagement {...} block explicitly or import a BOM. Importing a BOM is closer to “automatic” as you only need to specify the version of the BOM. The Spring Boot plugin adds a Spring Boot BOM, but without that plugin, you can add any BOM that you want.


(sergey.morenets) #3

Thank you, @jjustinic

It seems that the simplest solution is the following:

dependencyManagement {
     imports {
          mavenBom 'org.springframework.boot:spring-boot-starter-parent:2.0.0.RELEASE'
     }
}