Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link POM version and application version

I have two versions in my projects.

  1. The version in my POM.xml which is used when the project is packaged, etc.
  2. The version I have put in a constant in my code so I can use it during runtime when I log, etc.

These should of course be the same, but sometimes I forget to change one or the other.

Is there a good way to define this version only once and have it used by both maven and code during runtime?

like image 578
Svish Avatar asked Aug 29 '26 09:08

Svish


2 Answers

http://www.sonatype.com/books/mvnref-book/reference/resource-filtering-sect-description.html

Have a look at this, you should have a properties file, which has a certain property which refers to the version number. And using filtering you can set the version same both in maven artifact and application.

like image 121
Himanshu Bhardwaj Avatar answered Aug 31 '26 23:08

Himanshu Bhardwaj


When you package your application using Maven, Maven will generate a directory META-INF/maven/<groupId>/<artifactId>/pom.properties. That file contains the version of your project according to the POM, and you could load that file from the JAR file on runtime in order to read your version number.

Only thing is, this file does only exist in a packaged project (be it a JAR, a WAR or an EAR). You might want to write some fallback mechanism for when you are running the code from your workbench.

like image 30
mthmulders Avatar answered Aug 31 '26 22:08

mthmulders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!