DEV Community

Kamil
Kamil

Posted on • Updated on • Originally published at banach.net.pl

How to put pom.xml version and build date in properties?

While working on webapp API in Java I need to send the app version and the build date to the frontend. But how to make this?

As my API build is based on maven I thought about getting version from pom.xml file. So, let's make it this way!

Solution! Almost...

I need to put in the pom.xml file configuration responsible for resources filtering:

<build>
 <!-- clipped -->
   <resources>
     <resource>
       <directory>src/main/resources</directory>
       <filtering>true</filtering>
     </resource>
   </resources>
</build>
Enter fullscreen mode Exit fullscreen mode

And in the app.properties properties which will be replaced during build:

build.version=${pom.version}
build.date=${timestamp}
Enter fullscreen mode Exit fullscreen mode

After the build my app.properties is filled with expected data:

image

Now I can access version from POM and last build in Java app easily!

And fin^H^H... another problem?

Everything works smoothly, I can get the version from the pom.xml and also the build date. But... a favicon is now broken! What?!

Frontend is deployed along with backend (using Javalin static files feature and files were loaded from resources folder.

It turns out that the resource filtering plugin processe favicon.ico (in fact all .ico files) and broke them by saving them incorrectly. So I need to exclude those files from filtering!

Final solution

Final configuration in the pom.xml looks like in snippet below.

It processing all files in src/main/resources except all .ico files. But I want .ico in resource folder - so I need add them but without filtering (processing them).

<build>
 <!-- clipped -->
   <resources>
     <resource>
       <directory>src/main/resources</directory>
       <filtering>true</filtering>
       <excludes>
         <exclude>**/*.ico</exclude>
       </excludes>
     </resource>
     <resource>
       <directory>src/main/resources</directory>
       <filtering>false</filtering>
       <includes>
         <include>**/*.ico</include>
       </includes>
     </resource>
   </resources>
</build>
Enter fullscreen mode Exit fullscreen mode

And that's all - everything is now OK ;-)

Top comments (0)