64.2 Gradle依赖管理

spring-boot插件自动应用Dependency Management Plugin,并配置它导入spring-boot-starter-parent bom。这提供了跟Maven用户喜欢的相似依赖管理体验,例如,如果声明的依赖在bom中被管理的话,你就可以省略版本。为了充分使用该功能,只需要想通常那样声明依赖,但将版本号设置为空:

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.thymeleaf:thymeleaf-spring4")
    compile("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect")
}

你声明的spring-boot Gradle插件的版本决定了spring-boot-starter-parent bom导入的版本(确保可以重复构建)。你最好将spring-boot gradle插件版本跟Spring Boot版本保持一致,版本详细信息可以在附录中查看。

spring-boot插件对于没有指定版本的依赖只会提供一个版本。如果不想使用插件提供的版本,你可以像平常那样在声明依赖的时候指定版本。例如:

dependencies {
    compile("org.thymeleaf:thymeleaf-spring4:2.1.1.RELEASE")
}

Last updated