How to access maven.build.timestamp for resource filtering in Quarkus

Viewed 627

Accessing the version and name of the application works fine. But I also want to access the build date/time of a Quarkus application using maven. I know, there is a post for this already but I don't get it to work for Quarkus.

I have an application.properties file with:

# info properties
quarkus.application.version=1.0
quarkus.application.timestamp=${maven.build.timestamp}

In pom.xml, resource filtering is activated:

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>${version.resources-plugin}</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>process-resources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${basedir}/target/classes/META-INF/resources/</outputDirectory>
                <resources>
                    <resource>
                        <directory>name-frontend/dist/name-frontend</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

And in Java, accessing it via:

@ConfigProperty(name = "quarkus.application.version") // <--- works
String version;
@ConfigProperty(name = "quarkus.application.name") // <--- works
String name;
@ConfigProperty(name = "quarkus.application.timestamp") // <--- what to use here?
String buildDate;

Error:

Caused by: java.lang.RuntimeException: Failed to start quarkus
Caused by: java.util.NoSuchElementException: SRCFG00011: Could not expand value maven.build.timestamp in property quarkus.application.timestamp

Leaving the application.properties file without ${maven.build.timestamp} does let the build proceed, but there is simply no build time of course.

1 Answers

You likely want to use the Maven's Resource Filtering.

You would remove the maven-resources-plugin you have added, and simply configure Maven with:

<project>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
      ...
    </resources>
    ...
  </build>
  ...
</project>

Then quarkus.application.timestamp=${maven.build.timestamp} in application.properties will be replaced automatically when you perform a build.

Related