私は私のPOMの私のバージョン情報を保持:スプリングブート:いくつかのエンドポイントにPOMバージョン番号を簡単に表示する方法はありますか?
<version>2.0.0</version>
私はこの数が内に露出したい:
-
標準エンドポイント(理想的に/情報)
- の
- 1カスタム1
これを行う簡単な(自動)方法はありますか、またはプログラムで行うことはできますか?
私は私の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>
あなたは作成にプログラム的に内部に行うことができますjar:
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;
}