gpt4 book ai didi

spring-boot - 使用 Gradle 在 Spring Boot 项目中自定义属性

转载 作者:行者123 更新时间:2023-12-03 03:46:03 26 4
gpt4 key购买 nike

在我使用 gradle 构建的 Spring Boot 项目 (1.5.6.RELEASE) 中,我想包含一些自定义属性。 documentation 中列出的方法似乎不起作用(在构建时,我得到:Could not set unknown property 'additional' for task ':properties' of type org.gradle.api.tasks.diagnostics.PropertyReportTask.):

springBoot {
buildInfo {
properties {
additional = [
'a': 'alpha',
'b': 'bravo'
]
}
}
}

幸运的是我发现了这种方法here ,对我有用(没有编译错误,然后我可以从我的代码访问该属性):

springBoot{
buildInfo {
additionalProperties = [
'testpropertykey': 'testpropertyvalue'
]
}
}

但是,由于前者是“官方”记录的方法,我更愿意采用这种方法。我将如何使前一种方法起作用?我假设我遗漏了一些东西——除非文档有误,或者这可能是从 Spring Boot 1.5.6.RELEASE 更改而来的。

最佳答案

您链接的文档适用于插件的当前版本,该版本与 Spring Boot 的当前 GA 版本一致:2.1.7

插件的 1.5.x 版确实有一个 additionalProperties 字段:https://github.com/spring-projects/spring-boot/blob/1.5.x/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/buildinfo/BuildInfo.java#L66

2.1.x 版本没有,您使用 properties 代替:https://github.com/spring-projects/spring-boot/blob/2.1.x/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.java#L45

建议您迁移/升级到 Spring Boot 2.1.x 或 2.2.x,因为 1.5.x 已经达到 EOL:https://spring.io/blog/2018/07/30/spring-boot-1-x-eol-aug-1st-2019

关于spring-boot - 使用 Gradle 在 Spring Boot 项目中自定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57497693/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com