How to Export POM Project Version to Property File

Last Updated: 2021-11-19

Somehow I need to have a version defined in a property file, say a file at src/main/resources/config.prop


This should be the same version number defined in pom. However this file needs to be manually modified for every new release. Here's a solution to easily sync up the versions:

Step 1: add pom property to properties file


Step 2: add maven-resources-plugin to pom file


Step 3: setup section in pom

Set directory to src/main/resources. Set filtering to true so ${project.version} will be replaced by the actual project.version defined in pom


Step 4: compile

Compile the code

$ mvn install

find the "compiled" property file in target/classes/conf.prop, the ${project.version} should be replaced


Step 5: package the compiled file by assembly plugin