Injecting project version into Quarkus service’s welcome page

@cowtowncoder
1 min readDec 2, 2022

I started using Quarkus web framework quite recently (this year) and so far like it a lot. A lot of stuff comes out of the box; performance is good; documentation excellent. And so on. What’s not to like?

This includes generation of basic index.html to serve as the service welcome page, which is just a static HTML file.
One challenge with static files, however, is that including not-so-static information becomes challenging: in this case version number included changes during development (once per release).
So how can we make it dynamic? I’m sure there are many ways, but quick googling didn’t find me a solution to use. But I had done something similar before so…

Maven-replacer-plugin to the Rescue!

I had used maven-replacer-plugin with Jackson in the past: in that case, I auto-generate PackageVersion.java that gets compiled and becomes programmatically accessible during runtime.
Here we want to do similar templating but for a simple HTML file.

Here’s how

Here’s how I ended up solving the problem.
First: src/main/resources/META-INF/resources/index.html ) needs to have a “token” to replace formerly static version. I used something like:

<li>Version: <code>%VERSION%</code></li>

(instead of former <li>Version: v1.0.0</li> )

and then main change is to add another plugin definition within Maven pom.xml <build> section:

      <plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<ignoreMissingFile>false</ignoreMissingFile>
<file>${basedir}/src/main/resources/META-INF/resources/index.html</file>
<outputFile>${basedir}/target/classes/META-INF/resources/index.html</outputFile>
<replacements>
<replacement>
<token>%VERSION%</token>
<value>${project.version}</value>
</replacement>
</replacements>
</configuration>
</plugin>

And that’s it: resulting index.html uses Project version defined in pom.xml.

--

--

@cowtowncoder

Open Source developer, most known for Jackson data processor (nee “JSON library”), author of many, many other OSS libraries for Java, from ClassMate to Woodstox