我正在尝试将我的项目从 Maven 构建转换为 Gradle。目前项目使用Spring Boot。
在我当前的 Maven 配置中,我有
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate4</artifactId>
<version>${jackson.version}</version>
</dependency>
在上面的代码片段中,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 构建。
Thanks!
您可以使用依赖管理插件导入 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 时将默认开始使用依赖管理插件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)