[英]Managing Spring dependencies in Gradle
我在Gradle中使用Spring Boot框架。 我知道要包含一些Spring依赖项,而无需显式定义版本,就可以引用“启动器”。 该版本将由我选择的Spring Boot版本(即Spring Boot Gradle插件的版本)控制。 示例(不相关的Gradle代码被省略):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: BOOT_VERSION
classpath group: 'io.spring.gradle', name: 'dependency-management-plugin', version: DEP_MGMT_VERSION
}
}
...
dependencies {
compile 'org.springframework.boot:spring-boot'
testCompile 'org.springframework.boot:spring-boot-starter-test'
}
注意上面没有为我的应用程序依赖项定义任何明确的版本。
现在,假设我要包括一些Spring Cloud和Spring Integration依赖项。 例如:
compile 'org.springframework.integration:spring-integration-mqtt:some-version'
compile 'org.springframework.cloud:spring-cloud-netflix-eureka-server:some-other-version'
如何确保用于这些依赖项的版本与我的其他Spring Boot依赖项兼容? 我不能遗漏版本,因此Gradle插件似乎并没有处理这些依赖项(也许只处理了org.springframework.boot
组的用户)。
换句话说,是否有一种干净,安全的方法来确保我所有的 Spring依赖项(从Spring Boot,Spring Cloud等)一起工作?
在gradle脚本中使用启动器。
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:2.0.0.RELEASE")
compile ':spring-cloud-starter-config'
compile ':spring-cloud-starter-netflix-eureka-client'
compile ':spring-boot-starter-integration'
}
https://github.com/spring-gradle-plugins/dependency-management-plugin/blob/master/README.md
对于Spring Cloud,添加带有兼容的Cloud-to-Boot版本的dependencyManagement部分。 文档指出了哪些项目版本与相应的引导序列(1.4.x,1.5.x,2.x)兼容:
dependencyManagement {
imports {
mavenBom ':spring-cloud-dependencies:Finchley.M8'
}
}
Finchley构建并与Spring Boot 2.0.x一起使用,并且不能与Spring Boot 1.5.x一起使用。
Dalston和Edgware发行列车建立在Spring Boot 1.5.x上,并且不能与Spring Boot 2.0.x一起使用。
Camden发布系列基于Spring Boot 1.4.x构建,但也已在1.5.x上进行了测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.