Injecting project version into Quarkus service’s welcome page
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 I ended up solving the problem.
src/main/resources/META-INF/resources/index.html ) needs to have a “token” to replace formerly static version. I used something like:
(instead of former
<li>Version: v1.0.0</li> )
and then main change is to add another plugin definition within Maven
And that’s it: resulting
index.html uses Project version defined in