我把我的版本信息在我的POM:春季开机:有没有一种方法可以轻松地在某个终端显示POM版本号?
<version>2.0.0</version>
我想这个数字暴露到:
- 标准的一个端点(理想/信息)
- 自定义一个
有没有一种简单(自动)的方法来做到这一点,或可以通过编程方式完成?
我把我的版本信息在我的POM:春季开机:有没有一种方法可以轻松地在某个终端显示POM版本号?
<version>2.0.0</version>
我想这个数字暴露到:
有没有一种简单(自动)的方法来做到这一点,或可以通过编程方式完成?
spring-boot-maven-plugin
允许生成POM坐标和您可能希望执行器提供的其他属性。
https://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/build-info.html
Maven的目标信息,
https://docs.spring.io/spring-boot/docs/current/maven-plugin/build-info-mojo.html
spring-boot:build-info
的Maven的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>wendelsilverio</groupId>
<artifactId>hello-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Hello</name>
</project>
你可以做编程到内部创建罐子:
public String getVersion() {
String version = null;
// try to load from maven properties first
try {
Properties p = new Properties();
InputStream is = PomVersionMain.class
.getResourceAsStream("/META-INF/maven/wendelsilverio/hello-maven/pom.properties");
if (is != null) {
p.load(is);
version = p.getProperty("version", "");
}
} catch (Exception e) {
// ignore
}
// fallback to using Java API
if (version == null) {
Package aPackage = PomVersionMain.class.getPackage();
if (aPackage != null) {
version = aPackage.getImplementationVersion();
if (version == null) {
version = aPackage.getSpecificationVersion();
}
}
}
if (version == null) {
// we could not compute the version so use a blank
version = "Version could not compute";
}
return version;
}