如何在 quarkus 中特别获取应用程序的版本(由 pom.xml 中的标签版本定义)?

ale*_*der 1 microprofile quarkus

我从一个普通的 Java EE 应用程序转移到 quarkus.io。在 Java EE 中,我有一个属性文件, version=${project.version}并在 JAX RS 端点中读取此文件。这非常有效。

@GET
public Response getVersion() throws IOException {
    InputStream in = getClass().getClassLoader().getResourceAsStream("buildInfo.properties");
    if (in == null) {
        return Response.noContent().build();
    }
    Properties props = new Properties();
    props.load(in);
    JsonObjectBuilder propertiesBuilder = Json.createObjectBuilder();
    props.forEach((key, value) -> propertiesBuilder.add(key.toString(), value.toString()));
    return Response.ok(propertiesBuilder.build()).build();
}
Run Code Online (Sandbox Code Playgroud)

现在我在用quarkus和MicroProfile,不知道有没有更好的方法。

我使用 MicroProfile 的 ConfigProperty 设置进行了尝试。

@ConfigProperty(name = "version")
public String version;
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

Property project.version not found.

这是我的 pom 的构建部分。

<build>
    <finalName>quarkus</finalName>
    <plugins>
        <plugin>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-maven-plugin</artifactId>
            <version>1.0.0.CR2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>build</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${surefire-plugin.version}</version>
            <configuration>
                <systemProperties>
                    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                </systemProperties>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

有什么解决方案/更好的方法吗?

小智 6

尝试


@ConfigProperty(name = "quarkus.application.version")
String version;
Run Code Online (Sandbox Code Playgroud)

您也可以从清单中读取实现版本。