Spring Boot在Gradle中获取包的属性 [英] Spring Boot get property of a package in Gradle

查看:145
本文介绍了Spring Boot在Gradle中获取包的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的项目从Maven构建转换为Gradle.该项目当前使用Spring Boot.

Im trying to convert my project from Maven build to Gradle. The project currently uses Spring Boot.

在我当前的Maven配置中,

In my current maven config, I have

    <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插件,而我正在尝试使用下面的代码片段.

In the above snippet, the jackson.version property comes from Spring Boot pom. Now, in Gradle, i'm using the Spring Boot plugin and Im trying to use the below snippet of code..

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模块的版本.但是,这不会发生

In above, I'm expecting the spring Boot plugin to insert the version of jackson-hibernate4 module. But, this doesnt happen

关于如何实现这一目标的任何想法?我的意图是在整个项目中使用相同版本的jackson版本.

Any idea on how to achieve this? My intention is to use the same version of jackson builds across the project.

谢谢!

推荐答案

您可以使用依赖性管理插件以导入Spring Boot的Bom并访问其指定的属性.

You can use the dependency management plugin to import Spring Boot's bom and get access to the properties that it specifies.

这是您进行了必要更改的原始build.gradle文件:

Here's you original build.gradle file with the necessary changes:

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时将开始使用依赖项管理插件.

Spring Boot 1.3 will start using the dependency management plugin by default when it'll apply the plugin and import the bom for you.

这篇关于Spring Boot在Gradle中获取包的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆