Maven Filter Resources and Adding a Project Version

This is a simple filter approach for writing a project version to a file.

<build>
 <resources>
  <resource>
    <directory>src/main/webapp</directory>
    <includes>
      <include>**/*.version</include>
    </includes>
    <filtering>true</filtering>
  </resource>
 </resources>
</build>

This is the project structure (excluding unmanaged parts)

β”œβ”€β”€β”€src
β”‚   └───main
β”‚       β”œβ”€β”€β”€java
β”‚       β”‚   └─── [...]
β”‚       └───webapp
β”‚           β”œβ”€β”€β”€META-INF
β”‚           └───WEB-INF
β”‚               β”œβ”€β”€β”€cfg
β”‚               └───portal.version
└─── pom.xml

Content portal.version

${project.version}

This should be replaced with an artifact version pom.xml, but unfortunately nothing happens. What's wrong? Thank you in advance

+5
source share
2 answers

When you specify a resource element, the content filtered as a result is copied to the target / classes folder. To filter web application resources, you can configure the maven-war-plugin.

Although to get the version in most cases it is better to read the standard Maven properties file in your application, for example. META-INF\maven\<groupId>\<artifactId>\pom.properties

+4
source

-, .

+2

All Articles