Including the version in a Maven artifact

Recently I wanted to include the version of an artifact generated by a Maven build into a text file in that artifact. As Google and and good friends will help you with, I was pointed to this article that was exactly what I wanted.

Basically, create a /src/main/resources/version.txt file with the following content…

${project.version}

… then including the following snippet in your “build”…


<build>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
      <includes>
        <include>**/version.txt</include>
      </includes>
    </resource>
    <resource>
      <directory>src/main/resources</directory>
      <filtering>false</filtering>
      <excludes>
        <exclude>**/version.txt</exclude>
      </excludes>
    </resource>
  </resources>
</build>
Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...