Spring Boot获取Gradle中包的属性

我试图将我的项目从Maven构建转换为Gradle。 该项目目前使用Spring Boot。

在我目前的maven配置中,我有

 com.fasterxml.jackson.datatype jackson-datatype-hibernate4 ${jackson.version}  

在上面的代码片段中,jackson.version属性来自Spring Boot pom。 现在,在Gradle中,我正在使用Spring Boot插件,我正在尝试使用下面的代码片段。

 buildscript { repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.4.RELEASE") }} apply plugin: 'idea' apply plugin: 'spring-boot' apply plugin: 'java' dependencies { compile("com.fasterxml.jackson.datatype:jackson-datatype-hibernate4") } 

在上面,我期待spring Boot插件插入jackson-hibernate4模块的版本。 但是,这不会发生

有关如何实现这一点的任何想法? 我的目的是在整个项目中使用相同版本的jackson构建。

谢谢!

您可以使用依赖关系管理插件导入Spring Boot的bom并访问它指定的属性。

这是原始的build.gradle文件,包含必要的更改:

 buildscript { repositories { mavenCentral() } dependencies { classpath "org.springframework.boot:spring-boot-gradle-plugin:1.2.4.RELEASE" classpath "io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE" } } apply plugin: 'idea' apply plugin: 'spring-boot' apply plugin: 'java' apply plugin: 'io.spring.dependency-management' repositories { mavenCentral() } dependencyManagement { imports { mavenBom 'org.springframework.boot:spring-boot-starter-parent:1.2.4.RELEASE' } } ext { jacksonVersion = dependencyManagement.importedProperties['jackson.version'] } dependencies { compile("com.fasterxml.jackson.datatype:jackson-datatype-hibernate4:$jacksonVersion") } 

Spring Boot 1.3默认开始使用依赖管理插件,当它应用插件并为你导入bom时。