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][1] 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>[1]: https://stackoverflow.com/questions/3532135/using-maven-to-output-the-version-number-to-a-text-file

Please remember to subscribe to the newsletter or feed to stay up to date.

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 do not link to anything I do not use myself.