Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven 渐变依赖项版本属性_Maven_Gradle - Fatal编程技术网

Maven 渐变依赖项版本属性

Maven 渐变依赖项版本属性,maven,gradle,Maven,Gradle,我有多个具有相同组id和版本id的依赖项。 比如说, dependencies { compile "org.springframework.boot:spring-boot-starter-jetty:2.1.0.RELEASE" compile "org.springframework.boot:spring-boot-starter:2.1.0.RELEASE" testCompile group: 'junit', name: 'junit', version:

我有多个具有相同组id和版本id的依赖项。 比如说,

dependencies {
    compile "org.springframework.boot:spring-boot-starter-jetty:2.1.0.RELEASE"
    compile "org.springframework.boot:spring-boot-starter:2.1.0.RELEASE"
    testCompile group: 'junit', name: 'junit', version: '4.12'
}
我希望将2.1.0.RELEASE移动到定义一次的属性中。 这是一个,我将如何在maven做到这一点

<properties>
    <spring.boot.version>2.1.0.RELEASE</spring.boot.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
        <version>${spring.boot.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>${spring.boot.version}</version>
    </dependency>
</dependencies>
盖德·格雷德尔先生会的

如果我在属性名中使用dots
,它将无法生成。 同样,gradle.properties中的spring.boot.version属性失败,出现错误:

Could not get unknown property 'spring' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

简单地说,您不能直接使用
spring.boot.version
来引用使用相同名称定义的属性,因为在
中,在名为**boot**的对象中引用名为**version**的属性,该属性是名为**spring**
的对象的属性

…-boot starter:${project.ext[“spring.boot.Version”]}

这将允许您添加包含任意数量句点的属性。例如,在
gradle.properties
中,您有

hello.world=heellooo

那你就可以了


print“stackoverflow的世界说${project.ext[“hello.world”]}“
在您的构建脚本中。

为什么不使用spring引导和依赖项管理插件,如文档所述?”?1) 我不喜欢插件。在maven中,我没有使用任何插件。2) 另外,让我们假设我使用的不是springboot,而是一组第三方库,我希望在一个地方定义它们的版本属性<代码>编译“org.springframework.boot:springbootstarter:${project.ext['spring.boot.Version']}”
dependencies {
    compile "org.springframework.boot:spring-boot-starter:${springBootVersion}"
    compile "org.springframework.boot:spring-boot-starter-jetty:${springBootVersion}"
    testCompile group: 'junit', name: 'junit', version: '4.12'
}
Could not get unknown property 'spring' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.