[英]Access Maven property “developers” in application.yml (Spring Boot)
我想讓開發人員在 pom.xml 中定義,並在構建過程后將標記顯示在 application.yml 中。 不知何故,它適用於所有屬性,但開發人員。
這是在一個 Spring Boot 項目中,我希望在構建過程中填充屬性。
這是 pom.xml 的摘錄
<description>my description</description>
<developers>
<developer>
<id>12345</id>
<name>John Doe</name>
<email>john@doe.com</email>
</developer>
</developers>
這是在 application.yml 中
info:
description: "@project.description@"
developer: "@project.developers[0].id@"
它適用於描述,但不適用於開發人員。 我嘗試了很多變體,例如 ${..}, "@project.developers.0.id"。 似乎沒有任何工作。
如果有人有想法,我將不勝感激。
您可以使用這種優雅的方式從pom.xml
讀取開發人員id
或email
地址或任何值:
build-info.properties
BuildProperties
輕松從此文件中讀取值。pom.xml:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<developer>${project.developers[0].email}</developer>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
這將在META-INF
目錄下生成一個build-info.properties
文件,其內容如下:
build.artifact=<artifactId-from-pom>
build.group=<groupId-from-pom>
build.name=<name-from-pom>
build.time=<build-time>
build.version=<version-from-pom>
build.developer=<email-of-the-first-developer-from-pom>
然后你可以用 Spring 讀取值:
@Configuration
public class OpenApiConfiguration {
@Autowired
private BuildProperties buildProperties;
@Bean
public OpenAPI customOpenAPI()) {
return new OpenAPI().info(new Info()
.title(...)
.version(buildProperties.getVersion())
.contact(new Contact().email(buildProperties.get("developer"))));
}
}
閱讀:
我希望這會幫助你。
將其添加到屬性上並在 pom 和屬性文件上使用,例如:
<properties>
<team.name>John Doe</team.name>
</properties>
用於開發者數據:
<developers>
<developer>
<name>${team.name}</name>
...
並在應用程序中使用該屬性:
description: "@team.name@"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.